Brief Question

jac3130

Board Regular
Joined
Dec 21, 2012
Messages
131
I have one column of data with various numbers. I'm in need of a macro that will hide every instance of the number 4 in a cell. If possible, please include a quick explanation of what each part of the macro is doing so I can better understand the VBA language. Thank you for your help.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
hello jac3130
need a little more info
1. is it a column of single numbers and you want the row hidden or deleted that contains a 4
2. are there more than 1 number in each cell ie: 35423 and you want 3523 or 35-23 or -----
3. which column do you want this done to
cheers

kevin
 
Upvote 0
jac3130,

Maybe something like this.....

Assumes hiding rows that contain the discrete number 4 in column B.

Using AutoFilter

Code:
Sub Filter_4s()
'Assumes column to be column B
'Hides rows using AutoFilter
Range("B:B").AutoFilter Field:=1, Criteria1:="<>4"
End Sub


Sub UnFilter_4s()
'Assumes column to be column B
'Unhides rows
Range("B:B").AutoFilter
End Sub


Looping through range......

Code:
Sub Hide_4s()
'Assumes column to be column B
'Determine last row in B with data
LastRow = Range("B" & Rows.Count).End(xlUp).Row
'Define range to look at
Set MyRange = Range("B1:B" & LastRow)
'Loop through to find 4 and hide row
For Each Cell In MyRange
If Cell.Value = 4 Then Cell.Rows.Hidden = True
Next Cell
End Sub


Sub Show_4s()
'Unhide rows
'Assumes column to be column B
Range("B:B").Rows.Hidden = False
End Sub

Hope that helps
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,684
Members
449,048
Latest member
81jamesacct

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