macro to copy cell in each worksheet to blank worksheet

houndhen

New Member
Joined
Mar 30, 2007
Messages
11
Excel 2003 on Windows XP.

I have a workbook that has 40 tabs. I want to copy a cell value from each worksheet and paste it in a column on a new worksheet that I have created. I never was great at writing macros but haven't done any lately.

Each sheet name is the date it was created on - like 01042011. The names generally are a week apart but that may not hold exactly true. I am having a problem accessing each worksheet in a loop like for/next.

Could I use the (name) like 'sheet76' in the vba code?

Should I use something other than for/next?

Thanks,
Harold
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Excel 2003 on Windows XP.

I have a workbook that has 40 tabs. I want to copy a cell value from each worksheet and paste it in a column on a new worksheet that I have created. I never was great at writing macros but haven't done any lately.

Each sheet name is the date it was created on - like 01042011. The names generally are a week apart but that may not hold exactly true. I am having a problem accessing each worksheet in a loop like for/next.

Could I use the (name) like 'sheet76' in the vba code?

Should I use something other than for/next?

Thanks,
Harold

instead of calling by the tab name, you could use call them by...(and retrieve the tabname at the same time.

Code:
For i = 1 to sheets.count
    Sheets(i).select
    shtName = Sheets(i).Name
Next i
 
Upvote 0
Great! Thanks.

I will have to work on copying the cell value that I want and pasting it on the blank worksheet.
 
Upvote 0
Welcome to the Board!

Here's an example that you should be able to work with:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet<br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> ActiveWorkbook.Worksheets<br>            <SPAN style="color:#00007F">If</SPAN> ws.Name <> "Summary" <SPAN style="color:#00007F">Then</SPAN><br>                ws.Range("A1").Copy Sheets("Summary").Cells(Rows.Count, "A").End(xlUp).Offset(1)<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">Next</SPAN> ws<br>End <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

HTH,
 
Upvote 0
Man! Smitty. That is so much more efficient code than what I ended up with. I got mine to work but I like yours better. I will mark this solved.

Thanks,
Harold
 
Last edited:
Upvote 0
I will mark this solved.

No need to do that, just letting everyone know that your issue has been taken care of is all you need to do (there's no "Solved" function on this board and we're not likely to add it).

I'm glad that it worked for you, and please don't hesitate to post back again! That's why we're all here. :biggrin:
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,814
Members
452,945
Latest member
Bib195

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