How do I apply this Macro to more than one selected Cell

mcat800

New Member
Joined
Sep 7, 2011
Messages
2
A Newbie here and would like to know how I can alter the code to loop through selected cells.


Sub Trim7FromLeft()
If Len(ActiveCell) > 1 Then
ActiveCell = Right(ActiveCell, Len(ActiveCell) - 7)
End If
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try:
Rich (BB code):
Sub Trim7FromLeft()
Dim Cell As Range
    
    If TypeName(ActiveSheet) = "Worksheet" Then
        For Each Cell In Selection
            If Len(Cell.Value) > 1 Then
                Cell.Value = Mid(Cell.Value, 8)
            End If
        Next
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,593
Messages
6,179,791
Members
452,942
Latest member
VijayNewtoExcel

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