这就是我要完成的工作:
O,Q,Z,AC列中的第一个空白单元格是随机的,因为我每天都会获得不同的数据。
这就是我为O列拼凑而成的内容,但这是行不通的。
Sub BegBalance()
'
' BegBalance Macro
' Adding formula to pull in beginning balance
Dim lFirstBlank As Long, lLastRow As Long
Dim rRange As Range
Dim ws1 As Worksheet, ws2 As Worksheet
Dim srchres As Variant
Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")
lLastRow = Cells(Rows.Count, 3).End(xlUp).Row
lFirstBlank = _
Range("O2:O" & lLastRow).SpecialCells(xlCellTypeBlanks).Cells(1, 1).Row
Set rRange = Range("O" & lFirstBlank & ":O" & _
lLastRow).SpecialCells(xlCellTypeBlanks)
On Error Resume Next
srchres = Application.WorksheetFunction.VLookup(ws1.Range("B2"), ws2.Range("B:H"), 3, False)
On Error GoTo 0
If (IsEmpty(srchres)) Then
ws1.Range("O2").Formula = CVErr(Error)
Else
ws2.Range("O2").Value = srchres
End If
End Sub