Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need to apply VBA code to multiple Worksheets


I have this code listed below which is in a macro module. Is there a way
that I can apply this code to only the worksheet I am working in. I have
worksheets labeled January thru December and need to distinqiush between
the sheets.

Dim rng As Range
Dim lastrow As Long, r As Long, i As Integer
With Worksheets("January") <<----This needs to be a variable for each
sheet
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
r = 1
srow = r
Do
Do
r = r + 1
Loop Until .Cells(r, "a") = "Weekly Subtotal" Or r = lastrow
For i = 4 To 6
Set rng = .Range(.Cells(srow, i), .Cells(r - 1, i))
Cells(r, i) = Application.Sum(rng)
Next i
srow = r + 1
Loop Until srow lastrow
End With


--
parteegolfer
------------------------------------------------------------------------
parteegolfer's Profile: http://www.excelforum.com/member.php...o&userid=31951
View this thread: http://www.excelforum.com/showthread...hreadid=521533

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Need to apply VBA code to multiple Worksheets

Change

With Worksheets("January")

to

With Activesheet


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"parteegolfer"
wrote in message
news:parteegolfer.24knwy_1142192702.1115@excelforu m-nospam.com...

I have this code listed below which is in a macro module. Is there a way
that I can apply this code to only the worksheet I am working in. I have
worksheets labeled January thru December and need to distinqiush between
the sheets.

Dim rng As Range
Dim lastrow As Long, r As Long, i As Integer
With Worksheets("January") <<----This needs to be a variable for each
sheet
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
r = 1
srow = r
Do
Do
r = r + 1
Loop Until .Cells(r, "a") = "Weekly Subtotal" Or r = lastrow
For i = 4 To 6
Set rng = .Range(.Cells(srow, i), .Cells(r - 1, i))
Cells(r, i) = Application.Sum(rng)
Next i
srow = r + 1
Loop Until srow lastrow
End With


--
parteegolfer
------------------------------------------------------------------------
parteegolfer's Profile:

http://www.excelforum.com/member.php...o&userid=31951
View this thread: http://www.excelforum.com/showthread...hreadid=521533



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need to apply VBA code to multiple Worksheets


Thanks Bob this worked well!


--
parteegolfer
------------------------------------------------------------------------
parteegolfer's Profile: http://www.excelforum.com/member.php...o&userid=31951
View this thread: http://www.excelforum.com/showthread...hreadid=521533

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 to apply macro across multiple worksheets within a workbook murkaboris Excel Discussion (Misc queries) 4 April 9th 09 01:24 AM
Apply code to other worksheets Metrazal[_6_] Excel Programming 4 February 24th 06 06:57 AM
Apply Macro on Multiple Worksheets in a Workbook Agnes Excel Programming 0 September 24th 04 01:39 AM
Apply Macro on Multiple Worksheets in a Workbook Agnes Excel Programming 1 September 23rd 04 02:20 AM
Apply Macro on Multiple Worksheets in a Workbook Agnes Excel Programming 1 September 22nd 04 11:42 PM


All times are GMT +1. The time now is 07:34 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"