我在工作簿中有几张纸。在第一页中,我有客户名称和销售额。如下所示。
Prabhu
斯里尼瓦桑
每个都有工作表名称作为客户名称。就像工作表2的名字是Prabhu,工作表3的名字是Srinivasan。
除工作表1之外,所有工作表的销售额都位于B列的最后一行。
现在,我需要根据客户名称获取工作表1上每个客户的销售额。
Sub EachthroughLastSheet()
Dim i As Integer
For i = 2 To ThisWorkbook.Worksheets.Count
MsgBox ThisWorkbook.Worksheets(i).Name
Next
End Sub
答案 0 :(得分:1)
如果我对您的理解正确,那应该会有所帮助:
Sub EachthroughLastSheet()
Dim j As Long
Dim nameCust As String
Dim valueSales As String
Dim lastRow As Long, lastRow2 As Long
With Sheets("Sheet1")
lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
For j = 2 To lastRow
nameCust = .Cells(j, 1)
With Sheets(nameCust)
lastRow2 = .Cells(Rows.Count, 2).End(xlUp).Row
valueSales = .Range("B" & lastRow2).Value
End With
.Cells(j, 2) = valueSales
Next
End With
End Sub