Use an Input box to select a range
I am looking for assistance to enable a User to set a range ( either Rows, or Columns, or a Used range) by way of an input box. The following code example is where a User can select a cell for a cell to carry out "number format" procedure. How should I alter this code?
Code:
Sub NumberFormatFromCell()
'PURPOSE: Obtain A Range From A Cell User's Determines
Dim rng As Range
Dim FormatRuleInput As String
'Temporarily Hide Userform
Me.Hide
'Get A Range Address From The User
On Error Resume Next
Set rng = Application.InputBox( _
Title:="Range selection", _
Prompt:="Select a range to reverse", _
Type:=8)
On Error GoTo 0
'Test to ensure User Did not cancel
If rng Is Nothing Then
Me.Show 'unhide userform
Exit Sub
End If
'Set Variable to first cell in user's input (ensuring only 1 cell)
Set rng = rng.Cells(1, 1)
'Store Number Format Rule
FormatRuleInput = rng.NumberFormat
'Apply NumberFormat To User Selection
If TypeName(Selection) = "Range" Then
Selection.NumberFormat = FormatRuleInput
Else
MsgBox "Please select a range of cells before running this macro!"
End If
'Unhide Userform
Me.Show
End Sub