我正在處理Excel工作表,並需要記錄四個單元格的日期和四個當前值。在環路下方不斷打印,而不是兩個值的像這樣的日期:宏打印日期而不是複製值
Date DRI_1 DRI_2 DRI_3 PRI
3/1/2016 33.33333333 8.75 12 54.08333333
3/1/2016 2/2/1900 8.75 12 54.08333333
3/1/2016 33.33333333 1/8/1900 12 54.08333333
3/1/2016 33.33333333 8.75 12 54.08333333
的日期的日期和日期後的值之後的第三行後直接佔據第二行。
下面是從宏觀的VBA代碼:
Option ExplicitSub Copypaste() ' ' Copypaste Macro ' ' Keyboard Shortcut: Ctrl+p ' Dim i As Integer, j As Integer, k As Integer Dim this_date As Date Dim ls As Boolean
i = 2 j = 24 k = 0 this_date = DateValue(Now) ls = True Do While ls = True If IsEmpty(Cells(i, j).Value) = True Then For k = 1 To 3 Cells(i, j + k).Value = Cells(2, 19 + k).Value Next k Cells(i, 28).Value = Cells(3, 20).Value Cells(i, j).Value2 = this_date ls = False Else ls = True End If i = i + 1 If i > 1000 Then ls = False End If Loop End Sub
我是新來的宏,我不能找出爲什麼發生這種情況。這似乎是我的代碼的一個孤立的問題!
爲了避免將來出現此問題它們格式化爲一般情況下,您可以設置使用VBA單元格的數字格式。因此,例如,在'Cells(i,j + k).Value = Cells(2,19 + k).Value'行之後,可以有一行說'Cells(i,j + k).NumberFormat =「一般「將您粘貼值的單元格格式設置爲常規或任何其他數字格式,只要您認爲合適。 – asongtoruin
發佈作爲答案,而不是評論。我會說NumberFormat是正確的答案,而不是額外的複製和粘貼。 – JamesFaix