Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() If I want to apply a macro to all sheets except for a certain sheet, say sheet "source data", what should I do? Thank you for your help. below is my current code. Thank you for your help! Public Sub insertrowinallsheets() Dim sheet As Variant For Each sheet In ActiveWorkbook.Sheets sheet.Cells.Find("CostClub").EntireRow.Insert Next sheet End Sub -- minrufeng ------------------------------------------------------------------------ minrufeng's Profile: http://www.excelforum.com/member.php...o&userid=26208 View this thread: http://www.excelforum.com/showthread...hreadid=515068 |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
The following code snippet with give you the general idea of how to do this.
You just loop through all the sheets in the workbook and check the name of each sheet as you go. Sub DoSomething() Dim wb As Workbook Dim ws As Worksheet Dim strName As String Set wb = ActiveWorkbook For Each ws In wb.Worksheets strName = ws.Name If strName < "Sheet1" Then 'Do some thing here End If Next ws Set wb = Nothing End Sub -- Kevin Backmann "minrufeng" wrote: If I want to apply a macro to all sheets except for a certain sheet, say sheet "source data", what should I do? Thank you for your help. below is my current code. Thank you for your help! Public Sub insertrowinallsheets() Dim sheet As Variant For Each sheet In ActiveWorkbook.Sheets sheet.Cells.Find("CostClub").EntireRow.Insert Next sheet End Sub -- minrufeng ------------------------------------------------------------------------ minrufeng's Profile: http://www.excelforum.com/member.php...o&userid=26208 View this thread: http://www.excelforum.com/showthread...hreadid=515068 |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
And if that list of worksheets gets longer, sometimes it's easier to see in the
Select case structu Sub DoSomething2() Dim wb As Workbook Dim ws As Worksheet Set wb = ActiveWorkbook For Each ws In wb.Worksheets select case lcase(ws.name) case is = "source data", "anothersheet", "evenmore" 'do nothing case else 'Do some thing here End select Next ws Set wb = Nothing End Sub Make sure you type that list in lower case--that's what the select case is looking at. minrufeng wrote: If I want to apply a macro to all sheets except for a certain sheet, say sheet "source data", what should I do? Thank you for your help. below is my current code. Thank you for your help! Public Sub insertrowinallsheets() Dim sheet As Variant For Each sheet In ActiveWorkbook.Sheets sheet.Cells.Find("CostClub").EntireRow.Insert Next sheet End Sub -- minrufeng ------------------------------------------------------------------------ minrufeng's Profile: http://www.excelforum.com/member.php...o&userid=26208 View this thread: http://www.excelforum.com/showthread...hreadid=515068 -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() could you just use a IF statement and check the activeworksheets name property. If it matches the name you do not want to have the macro attached do nothing. "Dave Peterson" wrote: And if that list of worksheets gets longer, sometimes it's easier to see in the Select case structu Sub DoSomething2() Dim wb As Workbook Dim ws As Worksheet Set wb = ActiveWorkbook For Each ws In wb.Worksheets select case lcase(ws.name) case is = "source data", "anothersheet", "evenmore" 'do nothing case else 'Do some thing here End select Next ws Set wb = Nothing End Sub Make sure you type that list in lower case--that's what the select case is looking at. minrufeng wrote: If I want to apply a macro to all sheets except for a certain sheet, say sheet "source data", what should I do? Thank you for your help. below is my current code. Thank you for your help! Public Sub insertrowinallsheets() Dim sheet As Variant For Each sheet In ActiveWorkbook.Sheets sheet.Cells.Find("CostClub").EntireRow.Insert Next sheet End Sub -- minrufeng ------------------------------------------------------------------------ minrufeng's Profile: http://www.excelforum.com/member.php...o&userid=26208 View this thread: http://www.excelforum.com/showthread...hreadid=515068 -- Dave Peterson |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
When that list of worksheets gets long, I find that the select case structure
easier to read than a bunch of if/then/else statements. peterparker wrote: could you just use a IF statement and check the activeworksheets name property. If it matches the name you do not want to have the macro attached do nothing. "Dave Peterson" wrote: And if that list of worksheets gets longer, sometimes it's easier to see in the Select case structu Sub DoSomething2() Dim wb As Workbook Dim ws As Worksheet Set wb = ActiveWorkbook For Each ws In wb.Worksheets select case lcase(ws.name) case is = "source data", "anothersheet", "evenmore" 'do nothing case else 'Do some thing here End select Next ws Set wb = Nothing End Sub Make sure you type that list in lower case--that's what the select case is looking at. minrufeng wrote: If I want to apply a macro to all sheets except for a certain sheet, say sheet "source data", what should I do? Thank you for your help. below is my current code. Thank you for your help! Public Sub insertrowinallsheets() Dim sheet As Variant For Each sheet In ActiveWorkbook.Sheets sheet.Cells.Find("CostClub").EntireRow.Insert Next sheet End Sub -- minrufeng ------------------------------------------------------------------------ minrufeng's Profile: http://www.excelforum.com/member.php...o&userid=26208 View this thread: http://www.excelforum.com/showthread...hreadid=515068 -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Selecting Last Sheet | Excel Worksheet Functions | |||
Autofilter Lists across Multiple Sheets, Maintain Correct Referenc | Excel Worksheet Functions | |||
In 3 active sheets in wkbk, determine& display the # of sheets that have data | Excel Discussion (Misc queries) | |||
Closing File Error | Excel Discussion (Misc queries) | |||
Does excel recognise names rather than cells? | Excel Worksheet Functions |