ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro: Select visible cells only (https://www.excelbanter.com/excel-programming/383359-macro-select-visible-cells-only.html)

David T

Macro: Select visible cells only
 
Right now my macro is creating a new worksheet for each name in a range.
However, i want my macro to create only a new worksheet for each VISIBLE name
in a range because I filter this list. Please help!!!!


Sub name_sheets()
'will add a sheet, and name it
'for each name in column C
'from C6 down till it hits a blank row
Dim Rng As Range
Dim ListRng As Range
Dim LRow As Long

Set ListRng = Range(Range("c6"), Range("c6").End(xlDown))
For Each Rng In ListRng
If Rng.Text < "" Then
With Worksheets
.Add(after:=.Item(.Count)).Name = Rng.Text
End With
End If
Next Rng
End Sub



Trevor Shuttleworth

Macro: Select visible cells only
 
Set ListRng = Range(Range("c6"),
Range("c6").End(xlDown)).SpecialCells(xlCellTypeVi sible)

Regards

Trevor


"David T" wrote in message
...
Right now my macro is creating a new worksheet for each name in a range.
However, i want my macro to create only a new worksheet for each VISIBLE
name
in a range because I filter this list. Please help!!!!


Sub name_sheets()
'will add a sheet, and name it
'for each name in column C
'from C6 down till it hits a blank row
Dim Rng As Range
Dim ListRng As Range
Dim LRow As Long

Set ListRng = Range(Range("c6"), Range("c6").End(xlDown))
For Each Rng In ListRng
If Rng.Text < "" Then
With Worksheets
.Add(after:=.Item(.Count)).Name = Rng.Text
End With
End If
Next Rng
End Sub





Charles Chickering

Macro: Select visible cells only
 
Change This:
If Rng.Text < "" Then
To This:
If Rng.Text < "" And Not Rng.EntireRow.Hidden Then
--
Charles Chickering

"A good example is twice the value of good advice."


"David T" wrote:

Right now my macro is creating a new worksheet for each name in a range.
However, i want my macro to create only a new worksheet for each VISIBLE name
in a range because I filter this list. Please help!!!!


Sub name_sheets()
'will add a sheet, and name it
'for each name in column C
'from C6 down till it hits a blank row
Dim Rng As Range
Dim ListRng As Range
Dim LRow As Long

Set ListRng = Range(Range("c6"), Range("c6").End(xlDown))
For Each Rng In ListRng
If Rng.Text < "" Then
With Worksheets
.Add(after:=.Item(.Count)).Name = Rng.Text
End With
End If
Next Rng
End Sub




All times are GMT +1. The time now is 09:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com