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!
 

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
 

Forum statistics

Threads
1,085,565
Messages
5,384,474
Members
401,903
Latest member
MarBer

Some videos you may like

This Week's Hot Topics

Top