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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

l8t4meneomatrix

New Member
Joined
May 13, 2014
Messages
2
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,971
Messages
5,767,391
Members
425,410
Latest member
SmittyT

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
Top