Excel VBA: upper case space replacement for selected row

Hello experts,

Excel VBA: upper case space replacement
I would like to add to my personal.xlsb the following procedure.
1.      Display an input box with the following message: “Please select the row in which you want to upper case and replace spaces”.
2.      Upper case the various values and replace space by “_”.
3.      Log error handling: if user click on cancel button related to input box.
If you have questions, please contact me.
Thank  you very much for your help.
LVL 1
LD16Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Please give this a try...
Sub UpperCaseAndReplaceSpaceWithHyphen()
Dim ws As Worksheet
Dim RowRange As Range, aCell As Range
Dim lr As Long, lc As Long, Col As Long
On Error Resume Next
Set RowRange = Application.InputBox("Please select the row in which you want to upper case and replace spaces.", "Select Row!", Type:=8)
On Error GoTo 0

If RowRange Is Nothing Then
    MsgBox "You didn't select any row.", vbExclamation, "Action Cancelled!"
    Exit Sub
End If
Application.ScreenUpdating = False
lr = RowRange.Row
Set ws = RowRange.Parent
lc = ws.Cells(lr, Columns.Count).End(xlToLeft).Column
For Col = 1 To lc
    ws.Cells(lr, Col) = Replace(UCase(ws.Cells(lr, Col)), " ", "-")
Next Col
Application.ScreenUpdating = True
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LD16Author Commented:
Thank you very much. I will test it today.
LD16Author Commented:
Tested and it works! Thank you very much for your help!
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome! ☺️
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.