• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

add number on button press

I have a button a spreadsheet, it adds a number 1 to a cell once selected and unhides some rows. I need this number to go if the button is selected again and the rows are hidden.

Code:
'Hides row 75-85 on contract, different payee details'
Private Sub CommandButton1_Click()
  Sheet4.Cells(73, "C") = 1
  With Rows("75:85")
  .Select
  .EntireRow.Hidden = Not .EntireRow.Hidden
  End With
End Sub
 
Last edited by a moderator:
Try this...

Code:
Sheets("Sheet4").Cells(73, "C") = 1
 
  If Rows("75:85").Hidden = True Then
  Rows("75:85").Hidden = False
  Else
  Rows("75:85").EntireRow.Hidden = True
  End If
 
Hi

I am getting an error. Subscript out of range.

Code:
'Hides row 75-85 on contract, different payee details'
Private Sub CommandButton1_Click()
  Sheets("Sheet4").Cells(73, "C") = 1
  If Rows("75:85").Hidden = True Then
  Rows("75:85").Hidden = False
  Else
  Rows("75:85").EntireRow.Hidden = True
  End If
End Sub
 
Last edited by a moderator:
hello- Excel comes up with this complaint when it doesnt find something that it has been asked for...Here in this case I think the issue was with Sheet4..

Check if the below works

Code:
Sheet4.Cells(73, "C") = 1
 If Rows("75:85").Hidden = True Then
  Rows("75:85").Hidden = False
 Else
  Rows("75:85").EntireRow.Hidden = True
 End If
 
Should have explained properly in my 1st thread.

I have a button a spreadsheet, it adds a number 1 to a cell once selected and unhides some rows. I need this number to go (disappear) if the button is selected again and the rows are hidden.
 
My Bad ..!! misunderstood it completely, was just focusing on hide and unhide part...

see if the below is fine..

Code:
If Rows("75:85").Hidden = True Then
  Sheet4.Cells(73, "C") = 1
  Rows("75:85").Hidden = False
  Else
  Rows("75:85").EntireRow.Hidden = True
  Sheet4.Cells(73, "C").ClearContents
  End If
 
Back
Top