請問大神
我想讓運算後的數值寫到SHEET3裡面(自動往下填入,想做執行後記錄功能)
LF = Sheet3.Range("A1").End(xlDown).Row + 1
Sheet3.Cells(LF, 1) = Now
Sheet3.Cells(LF, 2) = C.Offset(0, 3).Value
Sheet3.Cells(LF, 3) = Sheet2.Range("G" & i).Value
我試了很久但會錯誤,請有空大大指點一下謝謝
Public Sub CUT()
i = 2
Do
i = i + 1
If Sheet2.Range("B" & i) = "" Then Exit Do
With Sheet1.Range("B2:B50")
Set C = .Find(Sheet2.Range("B" & i), LookIn:=xlValues)
If Not C Is Nothing Then
Sheet2.Range("G" & i).Value = Sheet2.Range("G" & i).Value - C.Offset(0, 3).Value
LF = Sheet3.Range("A1").End(xlDown).Row + 1
Sheet3.Cells(LF, 1) = Now
Sheet3.Cells(LF, 2) = C.Offset(0, 3).Value
Sheet3.Cells(LF, 3) = Sheet2.Range("G" & i).Value
MsgBox "ok"
End If
End With
Loop
End Sub
只有改一列LF = Sheet3.Range("A1").End(xlDown).Row + 1
改成LF = Sheet3.Range("A10000").End(xlUp).Row + 1
Public Sub CUT()
i = 2
Do
i = i + 1
If Sheet2.Range("B" & i) = "" Then Exit Do
With Sheet1.Range("B2:B50")
Set C = .Find(Sheet2.Range("B" & i), LookIn:=xlValues)
If Not C Is Nothing Then
Sheet2.Range("G" & i).Value = Sheet2.Range("G" & i).Value - C.Offset(0, 3).Value
LF = Sheet3.Range("A10000").End(xlUp).Row + 1
Sheet3.Cells(LF, 1) = Now
Sheet3.Cells(LF, 2) = C.Offset(0, 3).Value
Sheet3.Cells(LF, 3) = Sheet2.Range("G" & i).Value
MsgBox "ok"
End If
End With
Loop
End Sub
如果你被要求要使用 VBA 做為工作用的工具
就要學習 F8(逐行) 和 Shift+F8(逐程序) 找問題/原因
參考文章
如果沒有
就算了