part 2 - array

o array does not equal 8,18,54 for each sheet ...instead x,yx for each sheet are based on the following

x = where in col A this value exisits, "Total Income"
y = where in col A this value exisits, "Gross Profit"
z = where in col A this value exisits, "Net Income"
finnstoneAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Which column(s) will 'Total Income', 'Gross Profit' and 'Net Income' appear in?
0
finnstoneAuthor Commented:
col A
0
NorieAnalyst Assistant Commented:
That's the thing, based on the example file you uploaded earlier they aren't all in the same column.

You might see that if you run this updated code.
Sub GetTotals()
Dim wsTotals As Worksheet
Dim strShName As String
Dim I As Long
Dim J As Long
Dim K As Long
Dim col As Long
Dim arrCols As Variant
Dim arrRows As Variant
Dim Res As Variant

    Set wsTotals = Sheets.Add

    wsTotals.Range("B1:D1").Value = Array("ROW8", "ROW18", "ROW54")

    arrCols = Array("HX:SX", "TX:AEX", "AFX:AQX", "ARX:BCX", "BDX:BOX", "BPX:CAX")
    arrRows = Array("Total Income", "Gross Profit", "Net Income")

    For I = 1 To 50
        strShName = "CA" & Format(I, "000")
        col = 2
        
        With wsTotals
            .Cells(I + 2, 1).Value = strShName
            If Evaluate("ISREF('" & strShName & "'!A1)") Then
                For J = LBound(arrCols) To UBound(arrCols)
                    For K = LBound(arrRows) To UBound(arrRows)
                        Res = Application.Match(arrRows(K), Sheets(strShName).Columns(1), 0)
                        If Not IsError(Res) Then
                            .Cells(I + 2, col).Formula = "=SUM(" & strShName & "!" & Replace(arrCols(J), "X", Res) & ")"
                        End If
                        col = col + 1
                    Next K
                Next J
                
                Else
                .Cells(I + 2, 2).Resize(, 3).Value = "#N/A"
                End If
        End With
    Next I

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
finnstoneAuthor Commented:
i though i only gave you one tab. somehow you knew anyways!
0
finnstoneAuthor Commented:
THANKS
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.