Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Repeating some code on all worksheets


Hi,

I have some code that will find the bottom row of data, offset by a
couple of rows and paste a string.
I need this to repeat across all worksheets in the workbook.
can anyone give me the VBA for looping through all worksheets?

thanks in advance,
Matt


--
matpj
------------------------------------------------------------------------
matpj's Profile: http://www.excelforum.com/member.php...o&userid=21076
View this thread: http://www.excelforum.com/showthread...hreadid=500576

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Repeating some code on all worksheets


Sub LoopThroWShts()
Dim sh WorkSheets

For each sh in WorkSheets
Your code
Next

End Sub

Remember to qualify your ranges with sh as in sh.Range("a10:e25") or
sh.Cells(10, "a") as the case may be.

Myles


--
Myles
------------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=500576

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Repeating some code on all worksheets

Dim w as worksheet

For each w in activeworkbook.worksheets
---insert code
Next w

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Repeating some code on all worksheets


I have tride that:

Dim w As Worksheet

For Each w In ActiveWorkbook.Worksheets
Columns("A:A").Select
Selection.Find(What:="Grand Total", After:=ActiveCell,
LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Offset(2, 0).Select

ActiveCell.FormulaR1C1 = "Total Surplus"
Next w

but this just stays on the first worksheet


--
matpj
------------------------------------------------------------------------
matpj's Profile: http://www.excelforum.com/member.php...o&userid=21076
View this thread: http://www.excelforum.com/showthread...hreadid=500576

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Repeating some code on all worksheets

Hi Matt,

Try:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim LRow As Long
Const sStr As String = "TEST"

Set WB = ActiveWorkbook '<<==== CHANGE

For Each SH In WB.Worksheets
With SH
LRow = .Cells(Rows.Count, "A").End(xlUp)(3).Row
.Cells(LRow, "A") = sStr
End With
Next SH

End Sub
'<<=============

This assumes that Column A is used to determine the last used cell and the
location of the pasted string.

Change A to accord with your requirements.


---
Regards,
Norman


"matpj" wrote in
message ...

Hi,

I have some code that will find the bottom row of data, offset by a
couple of rows and paste a string.
I need this to repeat across all worksheets in the workbook.
can anyone give me the VBA for looping through all worksheets?

thanks in advance,
Matt


--
matpj
------------------------------------------------------------------------
matpj's Profile:
http://www.excelforum.com/member.php...o&userid=21076
View this thread: http://www.excelforum.com/showthread...hreadid=500576





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Repeating some code on all worksheets


To preserve your coding, two ways to get round:

Solution1:

For Each w In ActiveWorkbook.Worksheets
w.Columns("A:A").Select
Selection.Find(What:="Grand Total", After:=ActiveCell,
LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Offset(2, 0).Select

ActiveCell.FormulaR1C1 = "Total Surplus"
Next w

Solution 2:

For Each w In ActiveWorkbook.Worksheets
w.activate
Columns("A:A").Select
Selection.Find(What:="Grand Total", After:=ActiveCell,
LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Offset(2, 0).Select

ActiveCell.FormulaR1C1 = "Total Surplus"
Next w


--
Myles
------------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=500576

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Repeating some code on all worksheets

This is what Myles told you:

Remember to qualify your ranges with sh as in sh.Range("a10:e25") or
sh.Cells(10, "a") as the case may be.


--
Kind regards,

Niek Otten

"matpj" wrote in
message ...

I have tride that:

Dim w As Worksheet

For Each w In ActiveWorkbook.Worksheets
Columns("A:A").Select
Selection.Find(What:="Grand Total", After:=ActiveCell,
LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Offset(2, 0).Select

ActiveCell.FormulaR1C1 = "Total Surplus"
Next w

but this just stays on the first worksheet


--
matpj
------------------------------------------------------------------------
matpj's Profile:
http://www.excelforum.com/member.php...o&userid=21076
View this thread: http://www.excelforum.com/showthread...hreadid=500576



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
How do I display repeating text between worksheets only once on ta Paul New Users to Excel 1 August 11th 09 01:23 PM
How do i use the same name multiple times in repeating worksheets Chris.Daniels Excel Discussion (Misc queries) 1 October 11th 06 10:47 AM
Repeating macro procedure on several worksheets Shandy720[_6_] Excel Programming 3 October 11th 05 03:06 PM
How do I create repeating worksheets in one workbook and have it . DM HD Excel Discussion (Misc queries) 8 December 23rd 04 06:49 PM
Repeating code SiouxieQ Excel Programming 1 November 24th 04 01:09 PM


All times are GMT +1. The time now is 09:54 PM.

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"