简体   繁体   English

宏以列出多个工作表中的单元格值

[英]Macro to list cell values from multiple sheets

I need a Macro to list cell values from multiple sheets 我需要一个宏来列出多个工作表中的单元格值

On each Worksheet, ("A7") is the Clients Name and ("J65") is the USD Amount due or owed. 在每个工作表上,(“ A7”)是客户名称,(“ J65”)是到期或欠的美元金额。 ("J65") has a formula: =SUM(J35-H62), which is the result I have with my limited writing skills. (“ J65”)的公式为:= SUM(J35-H62),这是由于我的写作技巧有限而产生的结果。

I need a quick list on a blank sheet: 我需要一张空白纸上的快速清单:

Column A A栏
Don juan 唐璜

Column B B栏
$5,200.67 $ 5,200.67

I have a code that will put my sheets in order of amount("J65"), least to greatest, I need it to list in that order. 我有一个代码,可以将工作表按数量(“ J65”)的顺序排列,至少以最大顺序排列,我需要它按该顺序列出。 ("A7") the clients name, is also the name of the worksheet if that helps. (“ A7”)客户名称,如果有帮助的话,也是工作表的名称。 Thank you 谢谢

Try this one: 试试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM