Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default AutoFilter & Hidden Rows

Hi,

I'm trying to write some code so that I can filter out rows based on a
search a cell's comments box. I've managed (with the help of Dave and
Wouter, thanks guys) to produce the code at the bottom of this post and this
works very nicely, hiding alls rows that do not match the criteria entered
in the InputBox.

My problem now is that when I autofilter a range, I can drag cell contents
across the hidden rows and the data is only duplicated in the visible rows.
Fine, that's what I want. But with my code, I hide the appropriate rows,
drag a cell's contents down over the hidden rows, but when I unhide the
hidden rows I find that the data has been copied across all rows, visible
and hidden!

I notice that playing around with the macro recorder that there appears to
be a difference between "FillDown" and "AutoFill", see below. Can anyone
help with this curious difference? I always thought that AutoFilter only
hides rows anyway.

Best regards

John


MACRO RECORDER EXAMPLE

Selection.AutoFilter Field:=1, Criteria1:="Rabbit"
Range("G9").Select
ActiveCell.FormulaR1C1 = "Test Word 1"
Range("G9").Select
Selection.FillDown

Selection.AutoFilter Field:=1
Rows("16:19").Select
Selection.EntireRow.Hidden = True
Range("H9").Select
ActiveCell.FormulaR1C1 = "Test Word 2"
Range("H9").Select
Selection.AutoFill Destination:=Range("H9:H23"), Type:=xlFillDefault
Range("H9:H23").Select
Rows("15:20").Select
Selection.EntireRow.Hidden = False


SEARCH CELL COMMENTS PROCEDURE

Sub SearchCellComments()
Dim SearchTerm As String
Dim iRow As Long
Dim iCol As Long
Dim visRows As Long
Dim procRows As Long
'
If MsgBox("Is cell at top of comments filled list?", _
vbYesNo + vbQuestion, _
"Start Process") = vbNo Then Exit Sub
'
iCol = ActiveCell.Column
iRow = ActiveCell.Row
'
visRows = 0 'No. of visible rows
procRows = 0 'No. of processed rows

SearchTerm = LCase(InputBox(Prompt:="Please enter search term"))

Do
If IsEmpty(Cells(iRow, iCol)) Then
MsgBox "Current cell is empty"
Exit Do
End If

procRows = procRows + 1
If Cells(iRow, iCol).Comment Is Nothing Then
Rows(iRow).Hidden = True
Else
'If LCase(Cells(iRow, iCol).Comment.Text) = SearchTerm Then
If InStr((LCase(Cells(iRow, iCol).Comment.Text)), SearchTerm)
Then
Rows(iRow).Hidden = False
visRows = visRows + 1
Else
Rows(iRow).Hidden = True
End If
End If
iRow = iRow + 1
Loop

MsgBox CStr(visRows) & " of " & CStr(procRows) & " records found."
'Application.StatusBar = CStr(visRows) & " of " & CStr(procRows) & "
records found"
'Application.StatusBar = False
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
I need my Hidden Rows to stay hidden when I print the sheet. Rosaliewoo Excel Discussion (Misc queries) 2 July 20th 06 07:51 PM
Excel VBA - hidden rows / autofilter cata_and[_4_] Excel Programming 6 June 8th 04 08:54 AM
AutoFilter and Hidden Rows Greg Bloom Excel Programming 1 September 25th 03 11:16 PM
Is it possible to tell if a cell is hidden by 'Autofilter' Tom Ogilvy Excel Programming 2 September 6th 03 07:57 PM
Is it possible to tell if a cell is hidden by 'Autofilter' Dave Peterson[_3_] Excel Programming 0 September 1st 03 04:29 PM


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