Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Skipping a tab when with this macro

I am currently using this macro to populate a column with the names of each
tab I have in a workbook. I would like to be able to exclude a tab when this
macro runs. If the tab name is Sheet1, how would I exclude it from showing
up in my column?

For Each ws In Worksheets
i = i + 1
Cells((i + 3), 1) = ws.Name
Next

Thanks for your time!
-Kai
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Skipping a tab when with this macro

You could do this:-
Sub nnn()
For Each ws In Worksheets
i = i + 1
If ws.Name = ("Sheet1") Then
i = i - 1
GoTo 100
End If
Cells((i + 3), 1) = ws.Name
100
Next
End Sub

Mike


"Kai Cunningham" wrote:

I am currently using this macro to populate a column with the names of each
tab I have in a workbook. I would like to be able to exclude a tab when this
macro runs. If the tab name is Sheet1, how would I exclude it from showing
up in my column?

For Each ws In Worksheets
i = i + 1
Cells((i + 3), 1) = ws.Name
Next

Thanks for your time!
-Kai

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Skipping a tab when with this macro

simplify:

i = 3
For Each ws In Worksheets
If ws.Name < "Sheet1" Then
i = i + 1
Cells(i, 1) = ws.Name
End If
Next ws


"Mike H" wrote:

You could do this:-
Sub nnn()
For Each ws In Worksheets
i = i + 1
If ws.Name = ("Sheet1") Then
i = i - 1
GoTo 100
End If
Cells((i + 3), 1) = ws.Name
100
Next
End Sub

Mike


"Kai Cunningham" wrote:

I am currently using this macro to populate a column with the names of each
tab I have in a workbook. I would like to be able to exclude a tab when this
macro runs. If the tab name is Sheet1, how would I exclude it from showing
up in my column?

For Each ws In Worksheets
i = i + 1
Cells((i + 3), 1) = ws.Name
Next

Thanks for your time!
-Kai

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Skipping a tab when with this macro

For Each ws In Worksheets
if lcase(ws.name) = lcase("sheet1") then
'skip it
else
i = i + 1
Cells(i + 3, 1).value = ws.Name
end if
Next ws



Kai Cunningham wrote:

I am currently using this macro to populate a column with the names of each
tab I have in a workbook. I would like to be able to exclude a tab when this
macro runs. If the tab name is Sheet1, how would I exclude it from showing
up in my column?

For Each ws In Worksheets
i = i + 1
Cells((i + 3), 1) = ws.Name
Next

Thanks for your time!
-Kai


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Skipping a tab when with this macro

I just realized that I may need to skip more than one sheet when running the
macro. I have tried copying and pasting in the critical parts (if else
statement) with the other worksheet name, but it brings up a "For" error when
it gets to the "Next" statement whenever I try it. Any suggestions on how I
can set it up to be able to add more sheets to the "ignore list?" Thanks
again for the speedy replies and the time!
-Kai

"Dave Peterson" wrote:

For Each ws In Worksheets
if lcase(ws.name) = lcase("sheet1") then
'skip it
else
i = i + 1
Cells(i + 3, 1).value = ws.Name
end if
Next ws



Kai Cunningham wrote:

I am currently using this macro to populate a column with the names of each
tab I have in a workbook. I would like to be able to exclude a tab when this
macro runs. If the tab name is Sheet1, how would I exclude it from showing
up in my column?

For Each ws In Worksheets
i = i + 1
Cells((i + 3), 1) = ws.Name
Next

Thanks for your time!
-Kai


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Skipping a tab when with this macro

There are lots of different ways:

For Each ws In Worksheets
select case lcase(ws.name)
case is = lcase("sheet1"), lcase("Sheet2"),lcase("sheet 99")
'skip it
case else
i = i + 1
Cells(i + 3, 1).value = ws.Name
end select
Next ws

= = =
If you're careful, you don't need to include the lcase() stuff on this line:

case is = lcase("sheet1"), lcase("Sheet2"),lcase("sheet 99")
just make sure you type in lower case:
case is = "sheet1", "sheet2", "sheet 99"

==========
Another:

dim res as variant
dim NamesToSkip as variant

namestoskip = Array("sheet1","sheet3","sheet999")

For Each ws In Worksheets
res = application.match(ws.name,namestoskip,0)

if iserror(res) then
'skip it
else
i = i + 1
Cells(i + 3, 1).value = ws.Name
end if

Next ws



Kai Cunningham wrote:

I just realized that I may need to skip more than one sheet when running the
macro. I have tried copying and pasting in the critical parts (if else
statement) with the other worksheet name, but it brings up a "For" error when
it gets to the "Next" statement whenever I try it. Any suggestions on how I
can set it up to be able to add more sheets to the "ignore list?" Thanks
again for the speedy replies and the time!
-Kai

"Dave Peterson" wrote:

For Each ws In Worksheets
if lcase(ws.name) = lcase("sheet1") then
'skip it
else
i = i + 1
Cells(i + 3, 1).value = ws.Name
end if
Next ws



Kai Cunningham wrote:

I am currently using this macro to populate a column with the names of each
tab I have in a workbook. I would like to be able to exclude a tab when this
macro runs. If the tab name is Sheet1, how would I exclude it from showing
up in my column?

For Each ws In Worksheets
i = i + 1
Cells((i + 3), 1) = ws.Name
Next

Thanks for your time!
-Kai


--

Dave Peterson


--

Dave Peterson
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
reference row on another sheet skipping zeros but not skipping li. Brennan Downes Excel Discussion (Misc queries) 2 April 2nd 23 01:28 PM
Macro skipping DN Excel Programming 1 September 15th 06 04:04 PM
Macro Skipping a column? Darin Kramer Excel Programming 3 August 25th 06 09:43 AM
Macro - Skipping a line PaulPoll Excel Worksheet Functions 4 December 21st 04 12:43 AM
Macro skipping even rows Bob Phillips[_5_] Excel Programming 5 July 26th 03 12:29 PM


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