Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command button to reset excel form.

Status
Not open for further replies.

Bruce456

Programmer
Jan 27, 2013
1
AU
I am trying to create a button which will reset my excel sheet and highlight the cells which need to be selected/edited, whilst ignoring blank cells and formulated cells. At the moment the 1st part of the code works and the validation lists reset, however the 2nd part of the code does not appear to do anything at all. I'm completely new to VB so any help at all would be appreciated.

Sub ResetBox()

Dim r As Range
Dim r1 As Range
Set r = Range("B1").EntireColumn
On Error Resume Next
Set r2 = r.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0
If Not r2 Is Nothing Then
For Each Cell In r2
If Cell.Validation.Type = xlValidateList Then
Cell.Value = "--Select--" '< = make sure this matches
End If
Next
Else
MsgBox "No Data Validation Cells"
End If
End Sub

Private Sub CommandButton1_Click(myRange As Range)

Set myRange = Range("B4:B171")

If Cell.Validation.Type = xlValidateList Then
ActiveCell.Interior.ColorIndex = 10
End If

If myRange.Cell.Value = "" Then Exit Sub

If myRange.Cell.HasFormula = True Then Exit Sub

If myRange.Cell.Value > 0 Then
ActiveCell.Interior.ColorIndex = 11
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top