work4livinsean
Programmer
Hi,
I am trying to write a code that will let the user select a range with the mouse during a macro. I have found a code where the user can select the code before the macro is ran but the user may have to select many different ranges on many different sheets. I have been looking and looking and have not found any mouse events for VBA on selecting ranges. My plan is to create a loop that would first ask the user what range would he/she like to select --> the user selects the range --> the code executes --> asks the user if he/she would like select another range --> loop or end code. Maybe creating a msgbox that just says "After you have selected the range hit OK." This would work but could cause many problems. Stopping the code from executing until a range is selected would be desired. If anyone has any ideas/suggestions/codes I would greatly appreciate it. Here is the code for selecting a range before the macro is ran (I guess my code would look similar in a loop unless there is a better way to go about this):
Sub SelectRangeBefore()
' Make sure a range is selected
If Not TypeName(Selection) = "Range" Then
MsgBox "Please select a worksheet range and try again.", vbExclamation, _
"No Range Selected"
Else
'Code would execute here
MsgBox "You have already selected a range."
End If
End Sub
Thanks in advance!
I am trying to write a code that will let the user select a range with the mouse during a macro. I have found a code where the user can select the code before the macro is ran but the user may have to select many different ranges on many different sheets. I have been looking and looking and have not found any mouse events for VBA on selecting ranges. My plan is to create a loop that would first ask the user what range would he/she like to select --> the user selects the range --> the code executes --> asks the user if he/she would like select another range --> loop or end code. Maybe creating a msgbox that just says "After you have selected the range hit OK." This would work but could cause many problems. Stopping the code from executing until a range is selected would be desired. If anyone has any ideas/suggestions/codes I would greatly appreciate it. Here is the code for selecting a range before the macro is ran (I guess my code would look similar in a loop unless there is a better way to go about this):
Sub SelectRangeBefore()
' Make sure a range is selected
If Not TypeName(Selection) = "Range" Then
MsgBox "Please select a worksheet range and try again.", vbExclamation, _
"No Range Selected"
Else
'Code would execute here
MsgBox "You have already selected a range."
End If
End Sub
Thanks in advance!