我是 VBA 的新手,但我上瘾了!我创建了一个工作簿,以 2 周为单位跟踪加班,每个工作表有一个 2 周的时间段。我正在尝试调试的宏旨在将工作表中所做的任何更改传递到以下工作表。诀窍是一行中的数据可能在以下工作表中的另一行中,因此我尝试在宏中使用 VLookup 以保持其准确性。
Sub CarryForward()
Dim Answer As String
Answer = MsgBox("This should only be used for a PERMANENT crew change." & vbNewLine & "If you are adding a new person to the list," & vbNewLine & "please use the Re-Sort function." & vbNewLine & "Do you want to continue?", vbExclamation + vbYesNo, "Caution!")
If Answer = vbNo Then
Exit Sub
End If
Application.ScreenUpdating = False
Dim ActiveWorksheet As String
ActiveWorksheet = ActiveSheet.Name
For i = (ActiveSheet.Index + 1) To Sheets("DATA").Index - 1
For x = 5 To 25
Dim a As String
Dim b As String
a = "B" & x
b = "C" & x
ActiveSheet.Range(b).Value = Application.WorksheetFunction.VLookup(a, Sheets(ActiveWorksheet).Range("B5:C25"), 2, False)
Next x
Range("A3").Select
Next i
Sheets(ActiveWorksheet).Select
Application.CutCopyMode = False
Range("A3").Select
Application.ScreenUpdating = True
End Sub
我很确定这只是 VLookup 代码行中的语法错误。发布的许多帮助都接近我正在寻找的内容,只是没有让我越过终点线。
任何帮助,将不胜感激!