Hi Everyone! :) Need help, Single cmd button to run different COMMAND!

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi,
I am sure how i should explain this...
I have two codes below. that I want to place in one command button:
when I click if row is "" then hide....the next time i click again no matter what show all the cells irrespective..."" or <> ""
Like pause and play button that does both the thing....:biggrin:

Thanks for HELPING...
Pedie;)

Code:
Option Explicit
 
 
Sub test()
'
    Dim lstRng As Range
    Dim c As Range
 
    Set lstRng = Sheet1.Range("a1", Range("a65536").End(xlUp))
 
    For Each c In lstRng
        If c.Value = "" Then
            c.EntireRow.Hidden = True
        End If
    Next c
End Sub
Code:
Code to to unhide all cells

Please give some idea...thanks again
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try this

Code:
Sub ToggleRows()
    Dim c As Range
    Static LastVal as Boolean

    With Sheet1.Range("a1", Range("a65536").End(xlUp)
        For Each c in .Cells
            c.EntireRow.Hidden = ((CStr(c.Value) = "") And LastVal)
        Next c
    End With

    LastVal = Not LastVal

End Sub
 
Upvote 0
Code:
Receiving error
Syntax error
>> [COLOR=red]With Sheet13.Range("a1", Range("a65536").End(xlUp)[/COLOR]

I place the code in standard module...
 
Upvote 0
is plus make it minus if minus make it plus - the code below does...

As for me i need something...like on click unhide everthing.....next click hide if blank

Code:
Dim cell As Range
    Cells(1).Select
    
    For Each cell In Selection
        If Application.IsNumber(cell) Then
            cell.Value = cell.Value * -1
        End If
    Next cell
 
Upvote 0
This should take care of the syntax error.
If a button calls this routine:
Press the button and all rows will be visible
Pressing the button again and those rows that have a blank in column A will be hidden
Press the button again and all rows will be visible.
etc.

Code:
Sub ToggleRows()
    Dim c As Range
    Static LastVal as Boolean

    With Sheet1
        For Each c in Range(.Range("A1"), .Range("A65536).End(xlup))
            c.EntireRow.Hidden = ((CStr(c.Value) = "") And LastVal)
        Next c
    End With

    LastVal = Not LastVal

End Sub

If the "" is a true blank and not the result of a formula, using .SpecialCells(xlCellTypeBlanks) will be faster than looping.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,003
Members
448,935
Latest member
ijat

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