sparky2205
Well-known Member
- Joined
- Feb 6, 2013
- Messages
- 507
- Office Version
- 365
- 2016
- Platform
- Windows
Hi folks,
I am having a problem with an inputbox.
Specifically handling the situation where a user doesn't enter any information and presses OK.
I have dealt with this before, successfully, when the input to the inputbox is numbers or text.
However, my input is a range.
I have trawled through what I can find online but I haven't been successful in putting it all together.
This is what I have so far:
You will notice some commented code. I left it there for reference to show other things I had been trying, unsuccessfully.
The problems I'm having:
My range, r, is not being set, even when I select a range, so always evaluates to nothing.
When I leave the inputbox blank and press OK I get a message telling me there is a problem with my formula.
I am having a problem with an inputbox.
Specifically handling the situation where a user doesn't enter any information and presses OK.
I have dealt with this before, successfully, when the input to the inputbox is numbers or text.
However, my input is a range.
I have trawled through what I can find online but I haven't been successful in putting it all together.
This is what I have so far:
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
' 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
You will notice some commented code. I left it there for reference to show other things I had been trying, unsuccessfully.
The problems I'm having:
My range, r, is not being set, even when I select a range, so always evaluates to nothing.
When I leave the inputbox blank and press OK I get a message telling me there is a problem with my formula.