我試圖讓這個子程序工作。 (ws).Range(「E5」)。end(xldown).offset(1,0,0)如果數據不是0到循環並複製數據,我有一張數據(ws1) 0)VBA Two for Loop並將值收集到第二張
請幫
Sub Test()
Dim r As Integer
Dim c As Integer
Dim amount As Long
Dim account As Variant
Dim Acct As Range
Dim Amt As Range
Dim ws1 As Worksheet
Dim target As Range
Dim ws As Worksheet
Set ws1 = ActiveSheet
Set ws = Worksheets("Updated")
Set target = ws.Range("E5:E" & Range("E5").End(xlDown)).Select
ws1.Activate
Range("A8").Select
For r = 8 To ActiveCell.End(xlDown).Row
Cells(r, 1).Select
account = ActiveCell.Value
For c = 2 To ActiveCell.End(xlToRight).Column
ActiveCell.Offset(0, 1).Select
amount = ActiveCell.Value
If ActiveCell.Value <> 0 Then
target.Offset(1, 0).Value = amount
target.Range("E5").End(xlDown).Offset(0, 1) = account
End If
Next
Next
ActiveCell.Offset(1, 0).Select
End Sub
您有什麼問題? –
我想將Amount和Account變量的值複製到表單ws中,因爲它會循環顯示錶單ws應該一個接一個地獲取這些值的所有值 –
金額優先後跟帳戶? –