andydtaylor
Active Member
- Joined
- Feb 15, 2007
- Messages
- 360
- Office Version
- 2016
Hi,
I'd like to check if a user supplied string is single cell reference. My problem is that the below code comes back as vallid if I enter a range like B2:B4.
Can anyone suggest how I could fix this?
Thanks,
Andrew
I'd like to check if a user supplied string is single cell reference. My problem is that the below code comes back as vallid if I enter a range like B2:B4.
Can anyone suggest how I could fix this?
Thanks,
Andrew
Code:
Sub test2()
Dim UserAdd As String
UserAdd = InputBox("Enter your address")
'check if valid:
If ValidAddress(UserAdd) Then
MsgBox ("it's valid!")
Else
MsgBox ("it ain't valid!")
End If
End Sub
Function ValidAddress(strAddress As String) As Boolean
Dim r As Range
On Error Resume Next
Set r = Worksheets(1).Range(strAddress)
If Not r Is Nothing Then ValidAddress = True
End Function