macro to loop thru sheets and add info

T

Tommy

Want to create a macro/vba to make a stop in every worksheet of the open
workbook and insert company name in A1 (of course, insert a row in A1 first),
then go to the next sheet and do the same. Some of my files have 2
worksheets, some have 8, some have 25. Need to make sure macro works
regardless of the number of worksheets in a workbooks. Thanks.
 
J

Jacob Skaria

Try the below

Sub Macro()
For Each ws In Worksheets
ws.Rows(1).Insert
ws.Range("A1") = "Company name"
Next
End Sub

If this post helps click Yes
 
R

Rick Rothstein

This should do what you want (change the text for the company name
though)...
 
R

Rick Rothstein

Sorry for the incomplete message (there is some Ctrl key sequence nearby to
the Ctrl+V keystroke I tried to use that I occasionally hit by accident
which sends the document). Here is the code that I tried send...

Sub InsertCompanyName()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
WS.Rows(1).Insert xlShiftDown
WS.Range("A1") = "The Company Name"
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top