Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default macro to loop thru sheets and add info

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default macro to loop thru sheets and add info

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
---------------
Jacob Skaria


"Tommy" wrote:

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default macro to loop thru sheets and add info

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


--
Rick (MVP - Excel)


"Tommy" wrote in message
...
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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default macro to loop thru sheets and add info

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

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
This should do what you want (change the text for the company name
though)...


--
Rick (MVP - Excel)


"Tommy" wrote in message
...
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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro doesn't loop through sheets of books in specific folder Diddy Excel Programming 5 October 11th 08 08:18 PM
Loop thru some sheets in wkbk and call macro - better way? Mifty Excel Programming 2 September 5th 08 01:22 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
apply Macro to all sheets in workbook - loop [email protected] Excel Programming 3 July 19th 07 08:13 PM
Macro to loop thru sheets & return to a1 cell CassieM Excel Programming 5 April 21st 05 04:35 PM


All times are GMT +1. The time now is 09:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"