Copy Data from Same Cell in Multiple Sheets to One Sheet

awashington

New Member
Joined
Oct 18, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hey y'all!

I have a software that generates excel spreadsheets using a pre-determined template. I merge them into one workbook using a macro that then renames the sheet based on on the sheet's B2 cell value. I currently have indirect formulas on a summary sheet that can pull data from each of the added sheets, but its dependent on a manual entry of the B2 cell value so it can connect to the appropriate sheet name.

I'm trying to get the macro to loop through the worksheets and copy the B2 value into a column (range?) on the summary sheet, until there are no more sheets to copy from.

Basically, I need Sheet#!B2 to be copied to Sheet1!B2:B, where the active cell to enter the data on moves down a row on the destination sheet each loop. So Loop One would pull Sheet2!B2 to Sheet1!B2, and then Loop Two would pull Sheet3!B2 to Sheet1!B3 and so on and so forth. I also need the sheets to be defined by index number, not name.

VBA Code:
Sub MatterRename()

    Dim SummarySheet As Worksheet
    Dim ws As Worksheet
    Dim i As Integer

    Set ws = ThisWorkbook.Worksheets(1)
    Set rs = ThisWorkbook.Worksheets.Count
    
    For i = 2 To SummarySheet.Range("B2:B" & SummarySheet.Range("B2").End(xlDown).Row).Cells.Count + 2
    
        ws.Range("B2").Copy Destination:=SummarySheet.Cells(B2)
        
    Next
    
End Sub

where SummarySheet is the sheet I need the data copied to (which would be the 1st in the index), ws is the worksheet the data is being pulled from, and B2 is the location of the data (text) I need to copy across all of the worksheets (except for the SummarySheet)

I get a Run Time Error 13, Type: Mismatch, with Set rs = ThisWorkbook.Worksheets.Count highlighted.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I thought about that, but I don't need to sum the data, I just need the data to be copy & pasted. I also couldn't have the formula in the summary sheet to automatically update when I merge in the workbook, since I don't have sheet names to reference. If I'm doing it after, it doesn't save me any time from just copy & pasting the data manually.
 
Upvote 0
I thought about that, but I don't need to sum the data, I just need the data to be copy & pasted. I also couldn't have the formula in the summary sheet to automatically update when I merge in the workbook, since I don't have sheet names to reference. If I'm doing it after, it doesn't save me any time from just copy & pasting the data manually.
The example is SUM, but you could use formula including a plain =Sheet1!A1 to do the copy. Note that the sheet name needs single quotes if there's a space in the sheet name as in ='Sheet 1'!A1.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,173
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