Replacing Range of Selected Cells using VBA

l8t4meneomatrix

New Member
Joined
May 13, 2014
Messages
2
Hello everyone,

I'm currently using the following code for a macro that replaces the one and only active cell's space for an underscore:

Sub Hello()
'Finds and replaces spaces with an nothing
ActiveCell.Value = Replace(ActiveCell.Value, " ", "_")
ActiveCell.Offset(0, 1).Select
End Sub

_________________________________
What I'm trying to figure out next is how to replace the selected cell's value and not just the "active" one.

For example this is what happens when I select more than one cell and use the VBAmacro:

Before-
Active Cell: 21R VW 12345 54321
Additional Selected Cell: 32R AZ 12345 54321

After-
Active Cell: 21RVW1234554321
Additional Selected Cell: 32R AZ 12345 54321
__________________________________
I'm trying to avoid using the "Range" of cells of course. Thank you in advance!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
So you mean something like this?

Code:
Sub Hello()
Selection.Replace " ", "_", xlPart
End Sub

You sir, have made my day. I thought it would take way more character spaces but you've simplified it, simply simplified it. Thank you again :)
Also where's the "Thank you" button on this thread? o_Oa
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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