close

If I want to apply a macro to all sheets except for a certain sheet, say
sheet quot;source dataquot;, 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(quot;CostClubquot;).EntireRow.Insert
Next sheet
End Sub--
minrufeng
------------------------------------------------------------------------
minrufeng's Profile: www.excelforum.com/member.php...oamp;userid=26208
View this thread: www.excelforum.com/showthread...hreadid=515068The 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 lt;gt; quot;Sheet1quot; Then
'Do some thing here
End If
Next ws

Set wb = Nothing

End Sub
--
Kevin Backmannquot;minrufengquot; wrote:

gt;
gt; If I want to apply a macro to all sheets except for a certain sheet, say
gt; sheet quot;source dataquot;, what should I do? Thank you for your help. below is
gt; my current code. Thank you for your help!
gt;
gt; Public Sub insertrowinallsheets()
gt; Dim sheet As Variant
gt; For Each sheet In ActiveWorkbook.Sheets
gt; sheet.Cells.Find(quot;CostClubquot;).EntireRow.Insert
gt; Next sheet
gt; End Sub
gt;
gt;
gt; --
gt; minrufeng
gt; ------------------------------------------------------------------------
gt; minrufeng's Profile: www.excelforum.com/member.php...oamp;userid=26208
gt; View this thread: www.excelforum.com/showthread...hreadid=515068
gt;
gt;

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 = quot;source dataquot;, quot;anothersheetquot;, quot;evenmorequot;
'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:
gt;
gt; If I want to apply a macro to all sheets except for a certain sheet, say
gt; sheet quot;source dataquot;, what should I do? Thank you for your help. below is
gt; my current code. Thank you for your help!
gt;
gt; Public Sub insertrowinallsheets()
gt; Dim sheet As Variant
gt; For Each sheet In ActiveWorkbook.Sheets
gt; sheet.Cells.Find(quot;CostClubquot;).EntireRow.Insert
gt; Next sheet
gt; End Sub
gt;
gt; --
gt; minrufeng
gt; ------------------------------------------------------------------------
gt; minrufeng's Profile: www.excelforum.com/member.php...oamp;userid=26208
gt; View this thread: www.excelforum.com/showthread...hreadid=515068

--

Dave Peterson


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.
quot;Dave Petersonquot; wrote:

gt; And if that list of worksheets gets longer, sometimes it's easier to see in the
gt; Select case structu
gt;
gt; Sub DoSomething2()
gt;
gt; Dim wb As Workbook
gt; Dim ws As Worksheet
gt;
gt; Set wb = ActiveWorkbook
gt;
gt; For Each ws In wb.Worksheets
gt; select case lcase(ws.name)
gt; case is = quot;source dataquot;, quot;anothersheetquot;, quot;evenmorequot;
gt; 'do nothing
gt; case else
gt; 'Do some thing here
gt; End select
gt; Next ws
gt;
gt; Set wb = Nothing
gt;
gt; End Sub
gt;
gt; Make sure you type that list in lower case--that's what the select case is
gt; looking at.
gt;
gt; minrufeng wrote:
gt; gt;
gt; gt; If I want to apply a macro to all sheets except for a certain sheet, say
gt; gt; sheet quot;source dataquot;, what should I do? Thank you for your help. below is
gt; gt; my current code. Thank you for your help!
gt; gt;
gt; gt; Public Sub insertrowinallsheets()
gt; gt; Dim sheet As Variant
gt; gt; For Each sheet In ActiveWorkbook.Sheets
gt; gt; sheet.Cells.Find(quot;CostClubquot;).EntireRow.Insert
gt; gt; Next sheet
gt; gt; End Sub
gt; gt;
gt; gt; --
gt; gt; minrufeng
gt; gt; ------------------------------------------------------------------------
gt; gt; minrufeng's Profile: www.excelforum.com/member.php...oamp;userid=26208
gt; gt; View this thread: www.excelforum.com/showthread...hreadid=515068
gt;
gt; --
gt;
gt; Dave Peterson
gt;

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:
gt;
gt; could you just use a IF statement and check the activeworksheets name
gt; property. If it matches the name you do not want to have the macro attached
gt; do nothing.
gt; quot;Dave Petersonquot; wrote:
gt;
gt; gt; And if that list of worksheets gets longer, sometimes it's easier to see in the
gt; gt; Select case structu
gt; gt;
gt; gt; Sub DoSomething2()
gt; gt;
gt; gt; Dim wb As Workbook
gt; gt; Dim ws As Worksheet
gt; gt;
gt; gt; Set wb = ActiveWorkbook
gt; gt;
gt; gt; For Each ws In wb.Worksheets
gt; gt; select case lcase(ws.name)
gt; gt; case is = quot;source dataquot;, quot;anothersheetquot;, quot;evenmorequot;
gt; gt; 'do nothing
gt; gt; case else
gt; gt; 'Do some thing here
gt; gt; End select
gt; gt; Next ws
gt; gt;
gt; gt; Set wb = Nothing
gt; gt;
gt; gt; End Sub
gt; gt;
gt; gt; Make sure you type that list in lower case--that's what the select case is
gt; gt; looking at.
gt; gt;
gt; gt; minrufeng wrote:
gt; gt; gt;
gt; gt; gt; If I want to apply a macro to all sheets except for a certain sheet, say
gt; gt; gt; sheet quot;source dataquot;, what should I do? Thank you for your help. below is
gt; gt; gt; my current code. Thank you for your help!
gt; gt; gt;
gt; gt; gt; Public Sub insertrowinallsheets()
gt; gt; gt; Dim sheet As Variant
gt; gt; gt; For Each sheet In ActiveWorkbook.Sheets
gt; gt; gt; sheet.Cells.Find(quot;CostClubquot;).EntireRow.Insert
gt; gt; gt; Next sheet
gt; gt; gt; End Sub
gt; gt; gt;
gt; gt; gt; --
gt; gt; gt; minrufeng
gt; gt; gt; ------------------------------------------------------------------------
gt; gt; gt; minrufeng's Profile: www.excelforum.com/member.php...oamp;userid=26208
gt; gt; gt; View this thread: www.excelforum.com/showthread...hreadid=515068
gt; gt;
gt; gt; --
gt; gt;
gt; gt; Dave Peterson
gt; gt;

--

Dave Peterson

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()