**VBA**Add Numbers/Text to Beginning of Select CELLS

NEW_2VBA

Board Regular
Joined
Dec 15, 2015
Messages
106
Happy Friday!!

Is it possible to edit the code below to apply the change to all selected cells at once?

Currently a box appears requiring user input to add numbers or text to the beginning of selected cells. The code below below does not allow one input to update all selected cells; instead the box appears repeatedly for each cell selected. This means, if I highlight 5 cells to add '00' to the beginning of each cell, the box will appear 5 times and I have to type in '00' in each input box and the selected cells are then updated one at a time.

I would like to be able to highlight multiple cells, have one input box appear, type in the text/numbers to add to the beginning of cells, then press Enter & have all cells updated at once.

Dim c As Range
Dim myValue As Variant
For Each c In Selection
myValue = InputBox("Enter Numbers/Text to Add to Selected Cells")
If c.Value <> "" Then c.Value = myValue & c.Value
Next
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Also, I notice that unfiltered cells are included in the update when I highlight a range of cells within a filtered column --> is there a way to only apply this code to visible cells only if working with a filtered list?
 
Upvote 0
How about
VBA Code:
Dim c As Range
myValue = InputBox("Enter Numbers/Text to Add to Selected Cells")Dim myValue As Variant
For Each c In Selection.SpecialCells(xlVisible)
If c.Value <> "" Then c.Value = myValue & c.Value
Next
 
Upvote 0
It worked, thank you!!?
At first I received a Compile Error/Syntax Error message so I placed the "Dim myValue As Variant" text under "Dim c As Range", then it worked like a charm!

Dim c As Range
Dim myValue As Variant
myValue = InputBox("Enter Numbers/Text to Add to Selected Cells")
For Each c In Selection.SpecialCells(xlVisible)
If c.Value <> "" Then c.Value = myValue & c.Value
Next

I appreciate your help!!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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