Mr.Piccolo22
New Member
- Joined
- Feb 29, 2012
- Messages
- 14
I found the following code and it has worked for years, however today it stopped and I am not sure why.
It will add let's X in front of the number I wanted to add but now it will only add it to a majority of cells and then the rest leave alone. When I do select the cells that didn't change and try to run it again, it gives me and only in range error.
I have Windows 10, and Excel 365 if that helps.
I am not sure what broke and still learning VBA. Thank you for any help.
Mr.P
It will add let's X in front of the number I wanted to add but now it will only add it to a majority of cells and then the rest leave alone. When I do select the cells that didn't change and try to run it again, it gives me and only in range error.
I have Windows 10, and Excel 365 if that helps.
Code:
Sub Add_Text()
Dim cell As Range
Dim moretext As String
Dim thisrng As Range
On Error GoTo endit
whichside = InputBox("Left = 1 or Right =2")
Set thisrng = Range(ActiveCell.Address & "," & Selection.Address) _
.SpecialCells(xlCellTypeConstants, xlTextValues)
moretext = InputBox("Enter your Text")
If whichside = 1 Then
For Each cell In thisrng
cell.Value = moretext & cell.Value
Next
Else
For Each cell In thisrng
cell.Value = cell.Value & moretext
Next
End If
Exit Sub
endit:
MsgBox "only formulas in range"
End Sub
I am not sure what broke and still learning VBA. Thank you for any help.
Mr.P
Last edited: