Input Box

chrisaw100

New Member
Joined
Nov 8, 2011
Messages
4
Hi,

If I get a range from a user through an input box, am I able to parse out the range? I would like to loop through it and multiply current cell values by a percentage.

Here's my code to get the range from the user:

Set rRange = Application.InputBox(Prompt:= _
"Please select a range with your Mouse.", _
Title:="SPECIFY RANGE", Type:=8)


Thanks,

Chris
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Welcome to the board.

One way:
Code:
    On Error Resume Next
    Set rRange = Application.InputBox(Prompt:="Please select a range with your Mouse.", _
                                      Title:="SPECIFY RANGE", _
                                      Type:=8)
    On Error GoTo 0
    If rRange Is Nothing Then Exit Sub
    
    For Each cell In rRange
        If VarType(cell.Value) = vbDouble Then
            cell.Value = cell.Value * 1.01
        End If
    Next cell
 
Upvote 0
Welcome to the Board!

Here's one way:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> rRange <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> c <SPAN style="color:#00007F">As</SPAN> Range<br>    <br>    <SPAN style="color:#00007F">Set</SPAN> rRange = Application.InputBox(Prompt:= _<br>        "Please select a range with your Mouse.", _<br>        Title:="SPECIFY RANGE", Type:=8)<br>        <br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> Range(rRange.Address)<br>            c.Value = c.Value * 1.1<br>        <SPAN style="color:#00007F">Next</SPAN> c<br>        <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

HTH,
 
Upvote 0
Still another way....

Code:
Sub Foo()
Set rRange = Application.InputBox(Prompt:= _
"Please select a range with your Mouse.", _
Title:="SPECIFY RANGE", Type:=8)
m = Val(InputBox("Enter % (using a leading decimal, like .5 for 50%"))
Range("Z1").Value = m   ' Cell Z1 used here as temporary cell to house % multiple
Range("Z1").Copy
rRange.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
Range("Z1").Value = ""
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,271
Messages
6,177,608
Members
452,785
Latest member
3110vba

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