Dealing with blank entries on inputbox using range input type

Status
Not open for further replies.

sparky2205

Active Member
Joined
Feb 6, 2013
Messages
480
Office Version
  1. 365
  2. 2016
Platform
  1. 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:
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
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.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Status
Not open for further replies.

Forum statistics

Threads
1,214,985
Messages
6,122,607
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top