我需要一个宏来列出来自多个工作表的单元格值
在每个工作表上,(“A7”)是客户名称,(“J65”)是应付或欠款的美元金额。 (“J65”)有一个公式:= SUM(J35-H62),这是我的写作技巧有限的结果。
我需要在空白纸上快速列表:
A栏 唐娟
B栏 $ 5,200.67
我有一个代码可以将我的工作表按金额(“J65”)排列,最小到最大,我需要按顺序列出。 (“A7”)客户端名称,如果有帮助,也是工作表的名称。 谢谢
答案 0 :(得分:1)
试试这个:
Sub Create_Report()
Dim table()
Dim data_range As Range
Dim firstcell As Range
Dim lastcell As Range
Dim i As Long
Dim msg As String
If Not Worksheets("Report") Is Nothing Then
Worksheets("Report").Delete
End If
ReDim table(0 To Worksheets.Count - 1, 0 To 1)
For i = 1 To UBound(table, 1) + 1
table(i - 1, 0) = Worksheets(i).Range("A7")
table(i - 1, 1) = Worksheets(i).Range("J65")
Next i
msg = "You have to delete the sheet [Report] before creating the next report"
On Error GoTo handler
Worksheets.Add
ActiveSheet.Name = "Report"
Set firstcell = Cells(2, 1)
Set lastcell = Cells(UBound(table, 1) + 2, UBound(table, 2) + 1)
Set data_range = Range(firstcell, lastcell)
Range("A1").Value = "Name"
Range("B1").Value = "Due / owed"
data_range = table
data_range.Sort Key1:=Range("B1"), Order1:=xlAscending
Exit Sub
handler:
MsgBox (msg)
End Sub