Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Prevent selecting filtered rows in AutoFiltered Range

I have a giant spreadsheet of server information using autofilters for the
columns. One of the uses I have for this spreadsheet is for performing
repetitive tasks by using a macro that is manually activated once I have a
range of server names selected. When the macro is activated, it takes the
selected range of server names and writes them to a text file that is later
called from a batch file.

The only problem is that filtered (hidden) rows are being included in the
selection. Is there a way to prevent this in code? Here is my code that
handles the server name selection:

Sub WriteFile()
Dim OutputFile As String
OutputFile = "C:\scripts\selection.txt"

Dim myRange As Range
Set myRange = Selection

Open OutputFile For Output As #1

For Each rngCell In myRange.Cells

inhalt = Cells(rngCell.Row, rngCell.Column).Value

Print #1, inhalt

Next rngCell

Close #1
ServerTool.Show vbModal
End Sub


Thanks in advance,

Scott

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Prevent selecting filtered rows in AutoFiltered Range

Maybe...

set myrange = nothing
on error resume next
Set myRange = Selection.cells.specialcells(xlcelltypevisible)
on error goto 0

if myrange is nothing then
msgbox "selection is all hidden!"
exit sub
end if

ps.
Couldn't:
inhalt = Cells(rngCell.Row, rngCell.Column).Value
be:
inhalt = rngCell.Value



PcolaITGuy wrote:

I have a giant spreadsheet of server information using autofilters for the
columns. One of the uses I have for this spreadsheet is for performing
repetitive tasks by using a macro that is manually activated once I have a
range of server names selected. When the macro is activated, it takes the
selected range of server names and writes them to a text file that is later
called from a batch file.

The only problem is that filtered (hidden) rows are being included in the
selection. Is there a way to prevent this in code? Here is my code that
handles the server name selection:

Sub WriteFile()
Dim OutputFile As String
OutputFile = "C:\scripts\selection.txt"

Dim myRange As Range
Set myRange = Selection

Open OutputFile For Output As #1

For Each rngCell In myRange.Cells

inhalt = Cells(rngCell.Row, rngCell.Column).Value

Print #1, inhalt

Next rngCell

Close #1
ServerTool.Show vbModal
End Sub

Thanks in advance,

Scott


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Prevent selecting filtered rows in AutoFiltered Range

Try:
For Each rngCell In myRange.Cells.SpecialCells(xlCellTypeVisible)

or, if that doesn't work for some reason,

For Each rngCell In myRange.Cells
If Not rngCell.Hidden
Print #1, rngCell.Value
End if
Next

--
HTH,
George


"PcolaITGuy" wrote in message
...
I have a giant spreadsheet of server information using autofilters for the
columns. One of the uses I have for this spreadsheet is for performing
repetitive tasks by using a macro that is manually activated once I have a
range of server names selected. When the macro is activated, it takes the
selected range of server names and writes them to a text file that is
later
called from a batch file.

The only problem is that filtered (hidden) rows are being included in the
selection. Is there a way to prevent this in code? Here is my code that
handles the server name selection:

Sub WriteFile()
Dim OutputFile As String
OutputFile = "C:\scripts\selection.txt"

Dim myRange As Range
Set myRange = Selection

Open OutputFile For Output As #1

For Each rngCell In myRange.Cells

inhalt = Cells(rngCell.Row, rngCell.Column).Value

Print #1, inhalt

Next rngCell

Close #1
ServerTool.Show vbModal
End Sub


Thanks in advance,

Scott



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Prevent selecting filtered rows in AutoFiltered Range

Thanks guys for the advice. George...the first recommendation worked
perfectly, while the second gave me a strange pop-up that said simply "400".

I'm good to go!!

Thanks again,

Scott

"George Nicholson" wrote:

Try:
For Each rngCell In myRange.Cells.SpecialCells(xlCellTypeVisible)

or, if that doesn't work for some reason,

For Each rngCell In myRange.Cells
If Not rngCell.Hidden
Print #1, rngCell.Value
End if
Next

--
HTH,
George


"PcolaITGuy" wrote in message
...
I have a giant spreadsheet of server information using autofilters for the
columns. One of the uses I have for this spreadsheet is for performing
repetitive tasks by using a macro that is manually activated once I have a
range of server names selected. When the macro is activated, it takes the
selected range of server names and writes them to a text file that is
later
called from a batch file.

The only problem is that filtered (hidden) rows are being included in the
selection. Is there a way to prevent this in code? Here is my code that
handles the server name selection:

Sub WriteFile()
Dim OutputFile As String
OutputFile = "C:\scripts\selection.txt"

Dim myRange As Range
Set myRange = Selection

Open OutputFile For Output As #1

For Each rngCell In myRange.Cells

inhalt = Cells(rngCell.Row, rngCell.Column).Value

Print #1, inhalt

Next rngCell

Close #1
ServerTool.Show vbModal
End Sub


Thanks in advance,

Scott




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Prevent selecting filtered rows in AutoFiltered Range


Here's the final code:

Sub WriteFile()
Dim OutputFile As String
OutputFile = "C:\scripts\selection.txt"

Dim myRange As Range
Set myRange = Selection

Open OutputFile For Output As #1
For Each rngCell In myRange.Cells.SpecialCells(xlCellTypeVisible)
inhalt = Cells(rngCell.Row, rngCell.Column).Value

Print #1, inhalt
Next rngCell

Close #1
ServerTool.Show vbModal
'servertool is my form that uses the text file created

End Sub


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
selecting the first row after a filtered range Farooq Sheri Excel Programming 2 July 24th 06 11:01 AM
prevent row insert in a range of rows pcorbani Excel Programming 1 March 8th 06 02:01 PM
Selecting Column of Visible AutoFiltered Cells. Robert Christie[_3_] Excel Programming 9 January 12th 05 11:15 PM
Selecting autofiltered cells Annita Excel Programming 4 August 13th 04 06:22 PM
Selecting Filtered Items from Named range Soniya Excel Programming 2 August 20th 03 10:59 AM


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