Excel Macro - Drag Cells

J

JCO

Is it hard to change an existing macro from a hardcode selection so that the
macro works over an area that you selected with the mouse? Lets take
something easy like changing the Case to Proper Case (first letter of each
word is capitalized and all other letters are lowercase).

Sub ProperCase()
'Loop to cycle through each cell in the specified range.
For Each x In Range("C1:C5")
'There is not a Proper function in Visual Basic for Applications.
'So, you must use the worksheet function in the following form:
x.Value = Application.Proper(x.Value)
Next
End Sub

In this case, it is hardcoded for the range C1 to C5. I would like to Drag
and Select any area then run the Macro.
Is this possible?
Thanks
 
C

Chirag

Change the Range("C1:C5") to Selection. The macro would look like:

Sub ProperCase()
'Loop to cycle through each cell in the selected range.
For Each x In Selection
'There is not a Proper function in Visual Basic for Applications.
'So, you must use the worksheet function in the following form:
x.Value = Application.Proper(x.Value)
Next
End Sub

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top