Summing selected tables across multiple sheets

VBABeginer_Chappers

New Member
Joined
Mar 8, 2018
Messages
10
Hi
I have a Table B3:AD6 on multiple sheets (YYYY-Registration). Cell B1 shows the location of the vehicle.
I want to create a table on Sheet (Chart Output) that is the sum of selected tables from other sheets, which sheets are used depends upon the year selected and the Location selected via an InputBox.
The registrations are all listed on sheet (To Hide) C2:C26.
I started to use arrays but I only started using VBA last year so got somewhat confused:confused: with loops.

This is as far as I got

Sub Create_Table()


Dim Aircraft_Array(2 To 26)
Dim Table_Array(27, 2)
Dim Select_Year As String
Dim Sum_Array(27, 2)
Dim Select_Location As String


Select_Year = InputBox("Enter the Required year", "What is the Required Year?")
'Select_Location = InputBox("Enter the Required Location", "What is the Required Location?")


If Select_Year = vbNullString Then Exit Sub
'If Select_Location = vbNullString Then Exit Sub


For i = 2 To 26
Aircraft_Array(i) = Sheets("To Hide").Range("C" & i)




For X = 0 To 27
' Starts The Outer Loop


For Y = 0 To 2
' Starts the Inner Loop

Table_Array(X, Y) = Sheets(Select_Year & " " & Aircraft_Array(i)).Range(Cells(X + 3 & Y + 4), Cells(X + 6 & Y + 30))

Next Y


Next X


'MsgBox (Table_Array(2, 2))


Next i




End Sub

Any help would be appreciated.

Chappers
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi

I have managed to find answers to most of my issues with the following code:

Sub Populate_ChartOutput_Table1()


Dim RequiredYear As String
Dim RequiredSquadron As String
Dim CopyRow As Integer
Dim CopyColumn As Integer


RequiredYear = InputBox("Enter the Required year", "What is the required Year?")


If RequiredYear = vbNullString Then Exit Sub


RequiredLocation = InputBox("Enter the Required Location", "What is the required Location?")


If RequiredLocation = vbNullString Then ..........................................................................


Sheets("Chart Output").Range("C4:AD6").Clear


For i = 1 To Sheets.Count
Sheets(i).Activate




If Range("E1").Value = RequiredYear And Range("B1") = RequiredLocation Then


For CopyRow = 4 To 6


For CopyColumn = 3 To 30


Sheets("Chart Output").Cells(CopyRow, CopyColumn).Value = Sheets("Chart Output").Cells(CopyRow, CopyColumn) + ActiveSheet.Cells(CopyRow, CopyColumn)


Next CopyColumn


Next CopyRow


End If


Next i


End Sub


My current problem is when no Location is entered I don't want to exit the program like when no year is entered, I want the blue section to run for all locations.
I'm thinking that it would be something along the lines of an Or if RequiredLocation = Nil Then ................................ just prior to the blue section.

I would be grateful for any suggestions.

Chappers
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,186
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top