Gathering data from multiple worksheets

superkopite

Board Regular
Joined
Jun 28, 2007
Messages
54
Hi guys and gals,

It has been years since my last post! :)

I need to gather data from multiple worksheets to display on one page. For example for Every worksheet I want to grab the contents of A1, A2, I8 and G8.

I can do this manually, of course. But I wanted to see if there was a way to do this automatically, maybe with a macro, so that even if I add new worksheets, that data is captured.

Any ideas as to a starting point.

Many thanks, as always
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Depends what you want to do with the data.

Something like this could be a start:

Code:
Dim ws As Worksheet
Dim mystr as String


For Each ws In ThisWorkbook.Worksheets
   If ws.Name <> "Sheet1" Then
        mystr = mystr & ", " & ws.Range("A1").value & ", " & ws.Range("A2").value & ", " & ws.Range("I8").value & ", " & ws.Range("G8").value
   End If
Next rs
 
Upvote 0
Depends what you want to do with the data.

Something like this could be a start:

Code:
Dim ws As Worksheet
Dim mystr as String


For Each ws In ThisWorkbook.Worksheets
   If ws.Name <> "Sheet1" Then
        mystr = mystr & ", " & ws.Range("A1").value & ", " & ws.Range("A2").value & ", " & ws.Range("I8").value & ", " & ws.Range("G8").value
   End If
Next rs

Thanks mrshl, I think I can workout what this is going to do, however I fear I may have explained myself poorly originally.
I don't actually what to form a string from the various bits of data. I want to put them into individual cells. For example, column A on Invoices worksheet, would display the contents of A1 from all of the other worksheets, Column B would display the contents of A2 etc
 
Upvote 0
So in invoices A2 would be from the first sheet, A3 from the second etc?

How's this looking?

Code:
Dim ws As Worksheet
Dim mystr As String
Dim rownum As Long


rownum = 2


For Each ws In ThisWorkbook.Worksheets
   If ws.Name <> "Invoices" Then
        Sheets("Invoices").Cells(rownum, 1).Value = ws.Range("A1").Value
        Sheets("Invoices").Cells(rownum, 2).Value = ws.Range("A2").Value
        Sheets("Invoices").Cells(rownum, 3).Value = ws.Range("I8").Value
        Sheets("Invoices").Cells(rownum, 4).Value = ws.Range("G8").Value
        rownum = rownum + 1
   End If
Next rs
 
Last edited:
Upvote 0
So in invoices A2 would be from the first sheet, A3 from the second etc?

How's this looking?

Code:
Dim ws As Worksheet
Dim mystr As String
Dim rownum As Long


rownum = 2


For Each ws In ThisWorkbook.Worksheets
   If ws.Name <> "Invoices" Then
        Sheets("Invoices").Cells(rownum, 1).Value = ws.Range("A1").Value
        Sheets("Invoices").Cells(rownum, 2).Value = ws.Range("A2").Value
        Sheets("Invoices").Cells(rownum, 3).Value = ws.Range("I8").Value
        Sheets("Invoices").Cells(rownum, 4).Value = ws.Range("G8").Value
        rownum = rownum + 1
   End If
Next rs

Thanks that looks pretty spot on, I think that will do exactly what I need it to, I can tinker with it from there, but I am getting a Complie Error: Invlaid Next control variable ref on "Next rs"
 
Upvote 0
Think I worked it out

Next rs should have been Next ws

Looks like it is working now, so much thanks to you!!!!!

I love this fourm so much
 
Upvote 0

Forum statistics

Threads
1,221,526
Messages
6,160,340
Members
451,637
Latest member
hvp2262

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