Sub combine()
Dim inName, inNum, inCity As String
Dim IncNum As Integer
Dim temp As Range
Dim lrow As Long
Dim counter As Integer
Dim cityCells, sNameCells, sNumCells As Range
cityCells = Sheets("Sheet2").UsedRange.Columns(1).Cells
For Each Cell In cityCells
If Cell <> "" And Cell.Row <> 1 Then
inCity = Cell.Value
inName = Sheets("Sheet2").Cells(Cell.Row, 2)
inNum = Sheets("Sheet2").Cells(Cell.Row, 3)
Set temp = Sheets("Sheet1").Columns(1).Find(what:=inCity)
If temp Is Nothing Then
'find the last row of the existing sheet
lrowEx = Sheets("Sheet1").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
IncNum = Sheets("Sheet2").UsedRange.Columns.Count
For counter = 1 To IncNum
Sheets("Sheet1").Cells(lrow + 1, counter) = Cells(Cell.Row, counter)
Next counter
End If
End If
Next
End Sub
我从 Sheets("Sheet1").Cells(lrow + 1, counter) = Cells(Cell.Row, counter) 行中收到 object required 错误,有什么帮助吗?
我是vba btw的新手,任何关于上述代码的内容将不胜感激。