Extracting data from multiple worksheets, from differing number of rows

leeboh

New Member
Joined
Oct 17, 2017
Messages
7
Hi All,

I am working on a large project to determine all of the different fields that appear within a particular software system. I have a worksheet for every screen, with each worksheet detailing the Field names, along with other information.

I am looking to create a Master worksheet if it were (or summary worksheet) that shows all of the fields that appear across all of the different worksheets (screens).

The tricky part here is:

All of the Field names defined, start from Cell B7, but the total number of fields, i.e. the total rows the Field names spans, varies from worksheet to worksheet. And to make matters more complex, at the end of the listed fields, there are 2 blanks and then there is additional information continued, such as Links and Buttons information (which is not needed for the Master/Summary worksheet, but is needed in the individual worksheet it currently exists in).

Any thoughts of a formula on this?

Additionally, I also need to state which worksheet (Screen Name) the data was taken from. I can then later run a query of sorts to show duplicates as 1 result, detailing the multiple worksheets (Screen Names) in which they appear.

Any help would be greatly appreciated, this would solve a massive roadblock I'm facing with a large project at work.

Many thanks,



Lee
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi & welcome to the board.
How about this
Code:
Sub ListFields()

    Dim Ws As Worksheet
    Dim MstSht As Worksheet
    Dim NxtRw As Long
    
    Set MstSht = Sheets("[COLOR=#0000ff]Master[/COLOR]")
    For Each Ws In Worksheets
        If Not Ws.Name = "[COLOR=#0000ff]Master[/COLOR]" Then
            NxtRw = MstSht.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
            With Ws.Range("B7", Ws.Range("B7").End(xlDown))
                .Copy MstSht.Range("A" & NxtRw)
                MstSht.Range("B" & NxtRw).Resize(.Rows.Count).Value = Ws.Name
            End With
        End If
    Next Ws

End Sub
Changing the sheet name in blue to match your sheet name
 
Upvote 0
Hi,

Thank you for your quick response!

It seems to work relatively well, although it struggles where there is only 1 field record to return - it seems to pull in a few additional rows, blanks included.

Additionally, I'm having an issue where a worksheet which was no relevant data - the code has pulled over 1million rows of blank data into the Master, listing the worksheet name each time.

It's close, but not quite there yet.

Thanks,
Lee
 
Upvote 0
When you say
Additionally, I'm having an issue where a worksheet which was no relevant data
does this mean that B7 will be blank?, or is it more a matter of certain sheets should not be checked?
 
Upvote 0
In that case try
Code:
Sub ListFields()

    Dim Ws As Worksheet
    Dim MstSht As Worksheet
    Dim NxtRw As Long
    
    Set MstSht = Sheets("Master")
    For Each Ws In Worksheets
        If Not Ws.Name = "Master" Then
            NxtRw = MstSht.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
            If Len(Ws.Range("B7")) > 0 Then
                If Len(Ws.Range("B8")) = 0 Then
                    Ws.Range("B7").Copy MstSht.Range("A" & NxtRw)
                    MstSht.Range("B" & NxtRw).Value = Ws.Name
                Else
                    With Ws.Range("B7", Ws.Range("B7").End(xlDown))
                        .Copy MstSht.Range("A" & NxtRw)
                        MstSht.Range("B" & NxtRw).Resize(.Rows.Count).Value = Ws.Name
                    End With
                End If
            End If
        End If
    Next Ws

End Sub
for the 1%, is there any way of determining if there is anything to be copied?
 
Upvote 0
For now, as the impact is minimal - I have just added text 'None' in cells B7. This bit of code works incredibly well - thank you so much for your efforts, massively impressed :)
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
Just in case an issue does come up, is there a way I can exclude a worksheet in the code, from returning data to the Master worksheet?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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