sparky2205
Well-known Member
- Joined
- Feb 6, 2013
- Messages
- 507
- Office Version
- 365
- 2016
- Platform
- Windows
Hi folks,
I am having trouble handling particular cases when using a range input with an inputbox.
I want to capture when a user does not make an entry but still presses OK.
I have done this previously, successfully, when the input value is a number or text.
But with a range type specified for the input value a blank throws an error which I have been unable to capture.
I have seen a lot of suggestions online but I haven't managed to put it all together.
Here's what I have:
You will notice some commented code. I left this for reference to other things I have tried.
My issues:
Leaving blank value in the inputbox and pressing OK results in a message telling me there is a problem with my formula. No idea what that's about.
My range object r is not getting set, even when I select a range.
Any help much appreciated.
I am having trouble handling particular cases when using a range input with an inputbox.
I want to capture when a user does not make an entry but still presses OK.
I have done this previously, successfully, when the input value is a number or text.
But with a range type specified for the input value a blank throws an error which I have been unable to capture.
I have seen a lot of suggestions online but I haven't managed to put it all together.
Here's what I have:
Code:
Sub MergeCells()
Dim r As Range
Dim c As New Collection
' On Error Resume Next
' Set r = Application.InputBox("select range using your mouse", , , , , , , 8)
c.Add Application.InputBox("select range using your mouse", , , , , , , 8)
If TypeOf c(1) Is Range Then Set r = c(1)
Set c = New Collection
MsgBox Err.Number
' If Err.Number = 424 Then
' Exit Sub
' End If
If r Is Nothing Then
Exit Sub
ElseIf r = "" Then
Exit Sub
End If
r.Select
r.Merge
End Sub
My issues:
Leaving blank value in the inputbox and pressing OK results in a message telling me there is a problem with my formula. No idea what that's about.
My range object r is not getting set, even when I select a range.
Any help much appreciated.