尝试将“发票”数据保存到Excel工作簿中的“Salesbook”。我的代码不起作用。任何帮助都会很棒。 Excel说标识符不被识别...但为什么?它是!不是吗? ......这是代码 -
注意 - 以下代码有效。问题是我的工作表名称末尾有一个“空格”,因此标识符无法识别它。 FFS。
Sub UpdateSalesBook()
Dim rng As Range
Dim i As Long
Dim a As Long
Dim rng_dest As Range
Application.ScreenUpdating = False
i = 1
Set rng_dest = Sheets("Sales Book").Range("D:F")
' Find first empty row in columns D:G on sheet Sales Book
Do Until WorksheetFunction.CountA(rng_dest.Rows(i)) = 0
i = i + 1
Loop
'Copy range A23:D27 on sheet Invoice to Variant array
**Set rng = Sheets("Invoice").Range("A23:D27")** 'This is what excel doesn't recognise
' Copy rows containing values to sheet Sales Book
For a = 1 To rng.Rows.Count
If WorksheetFunction.CountA(rng.Rows(a)) <> 0 Then
rng_dest.Rows(i).Value = rng.Rows(a).Value
'Copy Invoice number
Sheets("Sales Book").Range("A" & i).Value = Sheets("Invoice").Range("C18").Value
'Copy Date
Sheets("Sales Book").Range("B" & i).Value = Sheets("Invoice").Range("C15").Value
'Copy Company name
Sheets("Sales Book").Range("C" & i).Value = Sheets("Invoice").Range("A7").Value
i = i + 1
End If
Next a
Application.ScreenUpdating = True
End Sub