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
我從表(「工作表Sheet」)得到一個對象所需的誤差。將細胞(lrow + 1,計數器)=細胞(Cell.Row,計數器)線,任何幫助?對象所需錯誤Sheet 1中
我是vba btw的新手,任何指出上述代碼的東西將不勝感激。
這是我的解決方案。我添加了另一個循環,你可以忽略它。 @Elias – user2600411