#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Hide Row If

I would like to hide all rows in Column J that do not contain text
"*899*" (part of account number, formatted as 000-899-000). The code
below doesn't do it. TIA

Sub HideProjectRows()
Dim intCounter As Integer
Dim Str As String

Str = "*899*"

With Sheets("Projects 05")
For intCounter = 2 To 487
If .Cells(intCounter, "J").Value < Str Then _
.Rows(intCounter).Hidden = True
Next intCounter
End With
End Sub

Greg

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Hide Row If

Sub HideProjectRows()
Dim intCounter As Integer
Dim Str As String

Str = "-899-"

With Sheets("Projects 05")
For intCounter = 2 To 487
If instr(.Cells(intCounter, "J").text , Str)0 Then _
.Rows(intCounter).Hidden = True
Next intCounter
End With
End Sub

--
HTH...

Jim Thomlinson


"GregR" wrote:

I would like to hide all rows in Column J that do not contain text
"*899*" (part of account number, formatted as 000-899-000). The code
below doesn't do it. TIA

Sub HideProjectRows()
Dim intCounter As Integer
Dim Str As String

Str = "*899*"

With Sheets("Projects 05")
For intCounter = 2 To 487
If .Cells(intCounter, "J").Value < Str Then _
.Rows(intCounter).Hidden = True
Next intCounter
End With
End Sub

Greg


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default Hide Row If

Try this code

the wild card concept does not work because when using a srting * is also
considered a character. You have different approaches but since yours seems
static enough (middle part) its safe to use Mid to remove the portion you
need to validate from the string variable you submit.

Sub HideProjectRows()
Dim intCounter As Long
Dim Str As String
Dim rng As Range
Dim valueCheck As String

Str = "899"

Set rng = Sheets("Projects 05").UsedRange.Rows ' Set sheet for all range
rows populated

With Sheets("Projects 05")
For intCounter = 2 To rng.Rows.Count ' to maximum rows populated
valueCheck = .Cells(intCounter, "J").Value 'Isolate string value
from row
valueCheck = Mid(valueCheck, 5, 3) 'Isolate validation portion
If valueCheck < Str Then
.Rows(intCounter).Hidden = True
End If
Next intCounter
End With

End Sub

Hope it helps
------------------------------------------------------------------------------------------

"GregR" wrote:

I would like to hide all rows in Column J that do not contain text
"*899*" (part of account number, formatted as 000-899-000). The code
below doesn't do it. TIA

Sub HideProjectRows()
Dim intCounter As Integer
Dim Str As String

Str = "*899*"

With Sheets("Projects 05")
For intCounter = 2 To 487
If .Cells(intCounter, "J").Value < Str Then _
.Rows(intCounter).Hidden = True
Next intCounter
End With
End Sub

Greg


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Hide Row If

Morning Greg,
I made a few changes to you code, You was try find a complete string
with your code. The code below will find the sub string. If it's not found,
it returns zero.

enjoy, Rick

PS: make sure to put in the "End if" statement after
..Rows(intCounter).Hidden = True
It was missing in your code...


Sub HideProjectRows()

Dim intCounter As Integer
Dim Str As String '

Str = "899"

With Sheets("Projects 05")
For intCounter = 2 To 487
If InStr(.Cells(intCounter, "J"), Str) = 0 Then
.Rows(intCounter).Hidden = True
End If
Next intCounter
End With
End Sub


"GregR" wrote in message
oups.com...
I would like to hide all rows in Column J that do not contain text
"*899*" (part of account number, formatted as 000-899-000). The code
below doesn't do it. TIA

Sub HideProjectRows()
Dim intCounter As Integer
Dim Str As String

Str = "*899*"

With Sheets("Projects 05")
For intCounter = 2 To 487
If .Cells(intCounter, "J").Value < Str Then _
.Rows(intCounter).Hidden = True
Next intCounter
End With
End Sub

Greg



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Hide Row If

Just to clarify, Greg's original code has an underscore at the end of the if
criteria as a line connector so the code did not need an end if. That being
said i think you might be right on the "= 0" now that I re-read the request.
My code was hiding all of the wrong stuff...
--
HTH...

Jim Thomlinson


"Rick Hansen" wrote:

Morning Greg,
I made a few changes to you code, You was try find a complete string
with your code. The code below will find the sub string. If it's not found,
it returns zero.

enjoy, Rick

PS: make sure to put in the "End if" statement after
..Rows(intCounter).Hidden = True
It was missing in your code...


Sub HideProjectRows()

Dim intCounter As Integer
Dim Str As String '

Str = "899"

With Sheets("Projects 05")
For intCounter = 2 To 487
If InStr(.Cells(intCounter, "J"), Str) = 0 Then
.Rows(intCounter).Hidden = True
End If
Next intCounter
End With
End Sub


"GregR" wrote in message
oups.com...
I would like to hide all rows in Column J that do not contain text
"*899*" (part of account number, formatted as 000-899-000). The code
below doesn't do it. TIA

Sub HideProjectRows()
Dim intCounter As Integer
Dim Str As String

Str = "*899*"

With Sheets("Projects 05")
For intCounter = 2 To 487
If .Cells(intCounter, "J").Value < Str Then _
.Rows(intCounter).Hidden = True
Next intCounter
End With
End Sub

Greg






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Hide Row If

Jim, Eric, Rick, you solved my dilemma, thank you

Greg

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
How do you hide/un-hide the grid lines ED Excel Discussion (Misc queries) 4 February 26th 13 03:22 PM
Want to Hide columns in spreadsheet but NOT hide data in chart. KrispyData Charts and Charting in Excel 1 March 20th 09 04:45 PM
Hide Unhide Hide again DTTODGG New Users to Excel 1 February 15th 06 03:22 PM
Hide And Un-hide Excel Toolbars Jim333[_4_] Excel Programming 3 July 2nd 05 08:00 PM
How do I hide a worksheet in Excel and use a password to un-hide . Dchung Excel Discussion (Misc queries) 3 December 2nd 04 06:24 AM


All times are GMT +1. The time now is 12:23 PM.

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"