Force InputBox to Select range in Column A

aejaz7

New Member
Joined
Nov 6, 2018
Messages
20
VBA Code:
Sub SelectionbyBox()
 
    Sheets("Sheet1").Activate
    Dim myRange As Range
    On Error GoTo inputerror
    Set myRange = Application.InputBox(Prompt:= _
        "Select Range", _
        Title:="Range Selection", Type:=8)
     If myRange Is Nothing Then Exit Sub
    Else
        myRange.Select
           End If
    Selection.Copy
    Range("D12").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
inputerror:
       MsgBox "Please select Any Cell"
End Sub

It is Possible to force inputbox to Select range only in column A or set other column to not selectable or any formula to end code if range selection is not in column A
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
You could do it so that the range acted on is always in column A of the cells the user chose.

VBA Code:
Sub SelectionbyBox()
    Dim myRange As Range

    Sheets("Sheet1").Activate
    
    On Error GoTo inputerror
    Set myRange = Application.InputBox(Prompt:= "Select Range", Title:="Range Selection", Type:=8)
    On Error Goto 0

    If myRange Is Nothing Then 
        Exit Sub: Rem Cancel Pressed
    Else
        Set myRange = myRange.EntireRow.Columns(1)
        Range("D12").Resize(myRange.Rows.Count, 1).Value = myRange.Value
    End If
Exit Sub
inputerror:
       MsgBox "Please select Any Cell"
End Sub
 
Upvote 0
You can easily check if the range selected is in column A or not
VBA Code:
If myRange Is Nothing Then Exit Sub

If myRange.Column = 1 And myRange.Columns.Count = 1 Then
    myRange.Copy 
    Range("D12").PasteSpecial Paste:=xlPasteValues
Else
    MsgBox "Please ensure you select a range in column A!"
End If
 
Upvote 0

Forum statistics

Threads
1,214,414
Messages
6,119,375
Members
448,888
Latest member
Arle8907

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