LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 47
Default Find a range using code

I have a column that has a list of site names. I need some sort of a
function that'll search through the column and hide each row that contains
the value of a string variable. the function will be run when I uncheck a
checkbox.

And then when I recheck the checkbox I need it to unhide those rows. I've
been trying to figure this out using a loop but I don't think I'm doing it
correctly.

According to the code that I've written it's supposed to start at the top of
the column and find the first instance of a cell that matches my Site
variable and then assign the row number to the StartRow variable and then
continuing until it finds the last instance of the Site variable and assign
the row number to the EndRow variable. And then I use the Rows(StartRow &
":" & EndRow).hidden = true function.

The problem with this is that it assumes that all of my sites are going to
be grouped together in a contiguous block, which will not always be the case.

Here's my code:
------------------------------------------------------------------------------------------
Dim SiteRange As String
Dim Counter As Int16 = 1
Dim SearchCriteria As String
Dim StartRow As String
Dim EndRow As String
Dim MyFilterRange As String



SiteRange = Sheets("Masson-Predator").Cells(Counter, 5) 'Start at
the top of the column.
SearchCriteria = "China Lake CLS"

Do Until SiteRange = SearchCriteria 'Loop through the cells in the
sites column.
StartRow = Counter
Counter = Counter + 1
Do Until SiteRange < SearchCriteria
EndRow = Counter - 1


MyFilterRange = StartRow & ":" & EndRow
Loop
Loop

If Me.cboChinaLakeCLS.Checked = False Then
Sheets("Masson-Predator").Rows(MyFilterRange).Hidden = True
Else
Sheets("Masson-Predator").Rows(MyFilterRange).Hidden = False
End If
-----------------------------------------------------------------------------------------------

Can anyone help me out with this one?
 
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
VBA Code - Find & Move Youlan Excel Discussion (Misc queries) 19 May 13th 08 11:42 PM
Code to find code D. Excel Discussion (Misc queries) 2 August 12th 07 06:16 PM
Find last row code Mike Milmoe Excel Discussion (Misc queries) 2 June 11th 07 08:48 PM
Why code for find() is not working jesmin Excel Discussion (Misc queries) 1 December 28th 05 08:43 PM
Find dates in a range; then sum values in that range by a criteria Anders Excel Discussion (Misc queries) 4 October 21st 05 03:41 PM


All times are GMT +1. The time now is 08:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"