Hiding range of rows

jimayers

Board Regular
Joined
Nov 14, 2010
Messages
99
Hello - I am having trouble with finding a value in cells in "A" (= "ethnic balance") and hiding rows in a certain range around the found value. Here is what I have started but cant get to work:
Sub HideRows()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim hRow, uRow, bRow As Range
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To Lastrow
If Cells(i, "A") = "ETHNIC BALANCE" Then
hRow = Range(i, "A").Row
bRow = Range(i + 3, "A").Row
uRow = Range(i - 8, "A").Row
Range.Row("uRow:hRow").Hide
Range.Row("hRow:dRow").Hide
End If

Next
Application.ScreenUpdating = False
End Sub

Thanks for your help and if possible point out my errors - Jim A
 
So... you're all figured out then?
The code I posted is doing what you asked for as I understand it. (We don't really need the 'i' after 'next' in this case, though it doesn't hurt.)
Right now it is case sensitive, looking only for all caps instances of 'ETHNIC BALANCE'. You can make it not case sensitive by inserting:
Option Compare Text at the very top of your code module, above any subs you might have.

Hope it helps.
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top