VBA Macros Conditional Button - extreme novice

LoraExcels

New Member
Joined
Dec 10, 2015
Messages
4
I've only just started learning programming in VBA for Excel.2013. I have a sheet with 9 columns and 60 rows. Note that Rows 1-25 consist of 9 columns but B through D are merged. I'm trying to add a command button that will hide the unwanted rows for me. The unwanted rows will be chosen through column D only affecting rows 26 through 50 when the cell reads zero. This is how I want the code to read: If cells D26:D50 equal 0 Then EntireRow.Hidden.

I've tried multiple codes, none of which work because they're too simple and missing objects. I've been receiving a lot of errors 13 and 424.

This is my code:

Sub HideRows_Click()
If ActiveSheet.Range("D26:D50").Value=0 Then EntireRow.Hidden = True
End If
End Sub

I'm going to continue watching VBA tutorials. Any help is appreciated.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try something like this...

Code:
[color=darkblue]Sub[/color] HideRows_Click()
    [color=darkblue]Dim[/color] cell [color=darkblue]As[/color] Range
    Application.ScreenUpdating = [color=darkblue]False[/color]
    [color=darkblue]For[/color] [color=darkblue]Each[/color] cell [color=darkblue]In[/color] ActiveSheet.Range("D26:D50")
        cell.EntireRow.Hidden = cell.Value = 0
    [color=darkblue]Next[/color] cell
    Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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