Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default 'ThisWorkbook' Macro Question

I have a macro that I want to run on all sheets except the first one.
Can I just put all the code in 'ThisWorkbook' and somehow tell it to
exclude the first sheet?

Thanks,
Dan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default 'ThisWorkbook' Macro Question

Depends on what it is and how you want it to fire. More info?

--
Don Guillett
SalesAid Software

"Dan R." wrote in message
oups.com...
I have a macro that I want to run on all sheets except the first one.
Can I just put all the code in 'ThisWorkbook' and somehow tell it to
exclude the first sheet?

Thanks,
Dan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default 'ThisWorkbook' Macro Question

For Each sh In Thisworkbook.Worksheets
If sh.Index < 1 Then 'or
If sh.name < "First Sheet" Then
'your code
End If
Next sh

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Dan R." wrote in message
oups.com...
I have a macro that I want to run on all sheets except the first one.
Can I just put all the code in 'ThisWorkbook' and somehow tell it to
exclude the first sheet?

Thanks,
Dan



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default 'ThisWorkbook' Macro Question

Using the sheet index you can, this excludes the first page and provides a
sample.
For i = 2 To Worksheets.Count
Sheets(i).Cells(1, 1) = "hi"
Next

--
--
-John
Please rate when your question is answered to help us and others know what
is helpful.

"Dan R." wrote in message
oups.com...
I have a macro that I want to run on all sheets except the first one.
Can I just put all the code in 'ThisWorkbook' and somehow tell it to
exclude the first sheet?

Thanks,
Dan



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default 'ThisWorkbook' Macro Question

Alright you guys are really going to have to humor me here because I'm
new to this... But by using Bob's example here's what I came up with:
(don't laugh)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim R As Integer
R = 3
For Each sh In Thisworkbook.Worksheets
If sh.name < "SUMMARY" Then
Do Until R = Cells(Rows.Count, 9).End(xlUp).Row
Select Case Cells(R, 9)
Case "X"
Cells(R, 10) = "Data1"
Cells(R, 11) = "1"
Case "Y"
Cells(R, 10) = "Data2"
Cells(R, 11) = "2"
Case "Z"
Cells(R, 10) = "Data3"
Cells(R, 11) = "3"
End Select
R = R + 1
Loop
End If
Next sh
End Sub

Basically I'm trying to populate values into Sheets 2-5 columns 10 and
11 by using the criteria specified in the Case statements and the code
above isnt working (for obvious reasons I'm sure).

Thanks,
-- Dan

John Bundy wrote:
Using the sheet index you can, this excludes the first page and provides a
sample.
For i = 2 To Worksheets.Count
Sheets(i).Cells(1, 1) = "hi"
Next

--
--
-John
Please rate when your question is answered to help us and others know what
is helpful.

"Dan R." wrote in message
oups.com...
I have a macro that I want to run on all sheets except the first one.
Can I just put all the code in 'ThisWorkbook' and somehow tell it to
exclude the first sheet?

Thanks,
Dan




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default 'ThisWorkbook' Macro Question

You need to properly qualify the objects

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim R As Long
For Each sh In Thisworkbook.Worksheets
If sh.name < "SUMMARY" Then
For R = 3 To sh.Cells(sh.Rows.Count, 9).End(xlUp).Row
Select Case sh.Cells(R, 9)
Case "X"
sh.Cells(R, 10) = "Data1"
sh.Cells(R, 11) = "1"
Case "Y"
sh.Cells(R, 10) = "Data2"
sh.Cells(R, 11) = "2"
Case "Z"
sh.Cells(R, 10) = "Data3"
sh.Cells(R, 11) = "3"
End Select
R = R + 1
Loop
End If
Next sh
End Sub


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Dan R." wrote in message
oups.com...
Alright you guys are really going to have to humor me here because I'm
new to this... But by using Bob's example here's what I came up with:
(don't laugh)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim R As Integer
R = 3
For Each sh In Thisworkbook.Worksheets
If sh.name < "SUMMARY" Then
Do Until R = Cells(Rows.Count, 9).End(xlUp).Row
Select Case Cells(R, 9)
Case "X"
Cells(R, 10) = "Data1"
Cells(R, 11) = "1"
Case "Y"
Cells(R, 10) = "Data2"
Cells(R, 11) = "2"
Case "Z"
Cells(R, 10) = "Data3"
Cells(R, 11) = "3"
End Select
R = R + 1
Loop
End If
Next sh
End Sub

Basically I'm trying to populate values into Sheets 2-5 columns 10 and
11 by using the criteria specified in the Case statements and the code
above isnt working (for obvious reasons I'm sure).

Thanks,
-- Dan

John Bundy wrote:
Using the sheet index you can, this excludes the first page and provides
a
sample.
For i = 2 To Worksheets.Count
Sheets(i).Cells(1, 1) = "hi"
Next

--
--
-John
Please rate when your question is answered to help us and others know
what
is helpful.

"Dan R." wrote in message
oups.com...
I have a macro that I want to run on all sheets except the first one.
Can I just put all the code in 'ThisWorkbook' and somehow tell it to
exclude the first sheet?

Thanks,
Dan




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default 'ThisWorkbook' Macro Question

Bob I'm getting a compile error 'Loop without Do' when I run this
code... I'm sorry but can you help me again please?

Thanks,
-- Dan

Bob Phillips wrote:
You need to properly qualify the objects

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim R As Long
For Each sh In Thisworkbook.Worksheets
If sh.name < "SUMMARY" Then
For R = 3 To sh.Cells(sh.Rows.Count, 9).End(xlUp).Row
Select Case sh.Cells(R, 9)
Case "X"
sh.Cells(R, 10) = "Data1"
sh.Cells(R, 11) = "1"
Case "Y"
sh.Cells(R, 10) = "Data2"
sh.Cells(R, 11) = "2"
Case "Z"
sh.Cells(R, 10) = "Data3"
sh.Cells(R, 11) = "3"
End Select
R = R + 1
Loop
End If
Next sh
End Sub


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Dan R." wrote in message
oups.com...
Alright you guys are really going to have to humor me here because I'm
new to this... But by using Bob's example here's what I came up with:
(don't laugh)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim R As Integer
R = 3
For Each sh In Thisworkbook.Worksheets
If sh.name < "SUMMARY" Then
Do Until R = Cells(Rows.Count, 9).End(xlUp).Row
Select Case Cells(R, 9)
Case "X"
Cells(R, 10) = "Data1"
Cells(R, 11) = "1"
Case "Y"
Cells(R, 10) = "Data2"
Cells(R, 11) = "2"
Case "Z"
Cells(R, 10) = "Data3"
Cells(R, 11) = "3"
End Select
R = R + 1
Loop
End If
Next sh
End Sub

Basically I'm trying to populate values into Sheets 2-5 columns 10 and
11 by using the criteria specified in the Case statements and the code
above isnt working (for obvious reasons I'm sure).

Thanks,
-- Dan

John Bundy wrote:
Using the sheet index you can, this excludes the first page and provides
a
sample.
For i = 2 To Worksheets.Count
Sheets(i).Cells(1, 1) = "hi"
Next

--
--
-John
Please rate when your question is answered to help us and others know
what
is helpful.

"Dan R." wrote in message
oups.com...
I have a macro that I want to run on all sheets except the first one.
Can I just put all the code in 'ThisWorkbook' and somehow tell it to
exclude the first sheet?

Thanks,
Dan



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 'ThisWorkbook' Macro Question

I think Bob changed horses in mid-stream:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim R As Long
For Each sh In Thisworkbook.Worksheets
If sh.name < "SUMMARY" Then
For R = 3 To sh.Cells(sh.Rows.Count, 9).End(xlUp).Row
Select Case sh.Cells(R, 9)
Case "X"
sh.Cells(R, 10) = "Data1"
sh.Cells(R, 11) = "1"
Case "Y"
sh.Cells(R, 10) = "Data2"
sh.Cells(R, 11) = "2"
Case "Z"
sh.Cells(R, 10) = "Data3"
sh.Cells(R, 11) = "3"
End Select
Next R
End If
Next sh
End Sub

"Dan R." wrote:

Bob I'm getting a compile error 'Loop without Do' when I run this
code... I'm sorry but can you help me again please?

Thanks,
-- Dan

Bob Phillips wrote:
You need to properly qualify the objects

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim R As Long
For Each sh In Thisworkbook.Worksheets
If sh.name < "SUMMARY" Then
For R = 3 To sh.Cells(sh.Rows.Count, 9).End(xlUp).Row
Select Case sh.Cells(R, 9)
Case "X"
sh.Cells(R, 10) = "Data1"
sh.Cells(R, 11) = "1"
Case "Y"
sh.Cells(R, 10) = "Data2"
sh.Cells(R, 11) = "2"
Case "Z"
sh.Cells(R, 10) = "Data3"
sh.Cells(R, 11) = "3"
End Select
R = R + 1
Loop
End If
Next sh
End Sub


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Dan R." wrote in message
oups.com...
Alright you guys are really going to have to humor me here because I'm
new to this... But by using Bob's example here's what I came up with:
(don't laugh)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim R As Integer
R = 3
For Each sh In Thisworkbook.Worksheets
If sh.name < "SUMMARY" Then
Do Until R = Cells(Rows.Count, 9).End(xlUp).Row
Select Case Cells(R, 9)
Case "X"
Cells(R, 10) = "Data1"
Cells(R, 11) = "1"
Case "Y"
Cells(R, 10) = "Data2"
Cells(R, 11) = "2"
Case "Z"
Cells(R, 10) = "Data3"
Cells(R, 11) = "3"
End Select
R = R + 1
Loop
End If
Next sh
End Sub

Basically I'm trying to populate values into Sheets 2-5 columns 10 and
11 by using the criteria specified in the Case statements and the code
above isnt working (for obvious reasons I'm sure).

Thanks,
-- Dan

John Bundy wrote:
Using the sheet index you can, this excludes the first page and provides
a
sample.
For i = 2 To Worksheets.Count
Sheets(i).Cells(1, 1) = "hi"
Next

--
--
-John
Please rate when your question is answered to help us and others know
what
is helpful.

"Dan R." wrote in message
oups.com...
I have a macro that I want to run on all sheets except the first one.
Can I just put all the code in 'ThisWorkbook' and somehow tell it to
exclude the first sheet?

Thanks,
Dan



--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default 'ThisWorkbook' Macro Question

Dan

Make these alterations. Might be what you need.

R = R + 1
Next R
End If
Next sh


Gord Dibben MS Excel MVP

On 19 Jan 2007 09:46:24 -0800, "Dan R." wrote:

Bob I'm getting a compile error 'Loop without Do' when I run this
code... I'm sorry but can you help me again please?

Thanks,
-- Dan

Bob Phillips wrote:
You need to properly qualify the objects

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim R As Long
For Each sh In Thisworkbook.Worksheets
If sh.name < "SUMMARY" Then
For R = 3 To sh.Cells(sh.Rows.Count, 9).End(xlUp).Row
Select Case sh.Cells(R, 9)
Case "X"
sh.Cells(R, 10) = "Data1"
sh.Cells(R, 11) = "1"
Case "Y"
sh.Cells(R, 10) = "Data2"
sh.Cells(R, 11) = "2"
Case "Z"
sh.Cells(R, 10) = "Data3"
sh.Cells(R, 11) = "3"
End Select
R = R + 1
Loop
End If
Next sh
End Sub


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Dan R." wrote in message
oups.com...
Alright you guys are really going to have to humor me here because I'm
new to this... But by using Bob's example here's what I came up with:
(don't laugh)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim R As Integer
R = 3
For Each sh In Thisworkbook.Worksheets
If sh.name < "SUMMARY" Then
Do Until R = Cells(Rows.Count, 9).End(xlUp).Row
Select Case Cells(R, 9)
Case "X"
Cells(R, 10) = "Data1"
Cells(R, 11) = "1"
Case "Y"
Cells(R, 10) = "Data2"
Cells(R, 11) = "2"
Case "Z"
Cells(R, 10) = "Data3"
Cells(R, 11) = "3"
End Select
R = R + 1
Loop
End If
Next sh
End Sub

Basically I'm trying to populate values into Sheets 2-5 columns 10 and
11 by using the criteria specified in the Case statements and the code
above isnt working (for obvious reasons I'm sure).

Thanks,
-- Dan

John Bundy wrote:
Using the sheet index you can, this excludes the first page and provides
a
sample.
For i = 2 To Worksheets.Count
Sheets(i).Cells(1, 1) = "hi"
Next

--
--
-John
Please rate when your question is answered to help us and others know
what
is helpful.

"Dan R." wrote in message
oups.com...
I have a macro that I want to run on all sheets except the first one.
Can I just put all the code in 'ThisWorkbook' and somehow tell it to
exclude the first sheet?

Thanks,
Dan



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
ThisWorkbook.Print question Dave Excel Discussion (Misc queries) 1 November 19th 07 05:55 PM
SAVE AS... WITHOUT COPYING THISWORKBOOK MACRO´S cbm Excel Programming 2 December 28th 06 12:01 PM
Module1 vs Thisworkbook for Macro Craigm[_16_] Excel Programming 4 June 28th 05 01:17 PM
ThisWorkbook module question Stuart[_5_] Excel Programming 3 July 17th 04 02:32 PM


All times are GMT +1. The time now is 05:16 AM.

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

About Us

"It's about Microsoft Excel"