October 15th, 2010, 12:12 pm
You can use the Application.Inputbox function to prompt the user to select a range. Note: The Application.Inputbox is different than the VBA InputBox.Using this method, the user can either manually enter a range such as B2:B500 or select it with the mouse.A couple of examples are below:Sub SelectRange() Dim rng As Range On Error GoTo x: Set rng = Application.InputBox(Prompt:="Select Range", Type:=8) rng.Value = "ABC" Exit Subx: If Err = 424 Then MsgBox "Cancel Selected" End IfEnd SubSub SelectRange2() Dim rng As Range Dim c As Range, ctr As Long On Error GoTo x: Set rng = Application.InputBox(Prompt:="Select Range", Type:=8) For Each c In rng.Cells ctr = ctr + 1 c.Value = ctr Next Exit Subx: If Err = 424 Then MsgBox "Cancel Selected" End IfEnd Sub
Last edited by
jpsnj on October 14th, 2010, 10:00 pm, edited 1 time in total.