albertc30
Well-known Member
- Joined
- May 7, 2012
- Messages
- 1,091
- Office Version
- 2019
- Platform
- Windows
Hi all.
I hope everyone is having a good weekend.
As for me, well here I am again.
I have found code and it was doing what I wanted to do but, I wanted to add a user msg to say user hasn't entered any data if this was the case, rather than just closing or stopping the code at that.
I managed to add the msgbox I wanted but I am now struggling with where to position my IF statments and/or Else if one is needed.
Where am I going wrong here please?
As per always, any help and advice is very much welcome.
Thanks everyone.
I hope everyone is having a good weekend.
As for me, well here I am again.
I have found code and it was doing what I wanted to do but, I wanted to add a user msg to say user hasn't entered any data if this was the case, rather than just closing or stopping the code at that.
I managed to add the msgbox I wanted but I am now struggling with where to position my IF statments and/or Else if one is needed.
Where am I going wrong here please?
VBA Code:
Private Sub CBUnHideSpecific_Click()
Dim sName As String, sht As Worksheet
sName = InputBox(prompt:="Enter Proforma number you want to search for:", Title:="Proforma search...")
If sName = "" Then
MsgBox "You have not entered any data!", vbInformation 'Getting this msg even IF I click on Cancel on the inputBox.
Exit Sub 'Works and exists here when clicking the Okay button if no data has been entered.
'Do I need another line of code?
Else
On Error Resume Next
Set sht = ActiveWorkbook.Sheets(sName)
On Error GoTo 0
If sht Is Nothing Then
MsgBox prompt:="The Proforma '" & sName & _
"' does not exist or it has been invoiced!", _
Buttons:=vbExclamation, Title:="Search result..."
Else
If sht.Visible = xlSheetHidden Then sht.Visible = xlSheetVisible
sht.Select
End If
End If
End Sub
As per always, any help and advice is very much welcome.
Thanks everyone.