Cell Formatting

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
Good Morning,

I need to format a few different cells in the following manners:

A1 has to always add a colon :)) after whatever is typed in by a user. Example- "F" in a cell becomes "F:"

A2 has to always be three digits- so if a user puts in "1", the cell shows "001" or if a user puts in "20" it shows as "020" and obviously a three digit number like "340" just stays "340".

A3 has to add an "'ly" to all single letter input codes. So a user might put in W 3, W-3, or W3 and I want it to show as "W'ly 3". However, sometimes the user might use NW 3, NW3, or NW3 and those should just format as "NW 3". So in conclusion, anytime a single letter (and number) are used, the letter should have "'ly" added to it and one space between the "'ly" and the number. And anytime two letters are used, they should just ensure there is a space between the two letter code and the number.

Thanks!
 
Well this is wacky....

So I logged out, restarted, and logged back into my work machine (a virtual citrix machine) and the coding is working perfectly now....I really don't understand why....

Anyway.

Assuming it keeps working, thank you very very much for the help. These formatting coding pieces just haven't clicked for me yet!
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Sorry for late reply, had 'real' work to do.

Glad you're sorted (y)

Hey @Paul Ked

This is working like a champ. I'd like to make one change- if I want the user to be able to input "WNW 3" or another three letter code, it auto changes to two letters. Can I just add a into the existing code a letter to stop that? Basically all two and three letter combos are fine, and the single letter combos get changed to add the " 'ly " onto them.

Thanks!
 
Upvote 0
Sorry for late reply, had 'real' work to do.

Glad you're sorted (y)

Hey @Paul Ked

This is working like a champ. I'd like to make one change- if I want the user to be able to input "WNW 3" or another three letter code, it auto changes to two letters. Can I just add a into the existing code a letter to stop that? Basically all two and three letter combos are fine, and the single letter combos get changed to add the " 'ly " onto them.

Thanks!
 
Upvote 0
Hi there

Try:

Code:
    If Target.Address = ("$R$13") Then
        r13 = Range("R13")
        If Mid(r13, 3, 1) Like "[a-zA-Z]" Then
            r13 = Left(r13, 3) & " " & Right(r13, 1)
            Range("R13") = UCase(r13)
        ElseIf Mid(r13, 2, 1) Like "[a-zA-Z]" Then
            r13 = Left(r13, 2) & " " & Right(r13, 1)
            Range("R13") = UCase(r13)
        Else
            r13 = UCase(Left(r13, 1)) & "'ly " & Right(r13, 1)
            Range("R13") = r13
        End If
    End If

Obviously with whichever cells it needs!
 
Last edited:
Upvote 0
Hi there

Try:

Code:
    If Target.Address = ("$R$13") Then
        r13 = Range("R13")
        If Mid(r13, 3, 1) Like "[a-zA-Z]" Then
            r13 = Left(r13, 3) & " " & Right(r13, 1)
            Range("R13") = UCase(r13)
        ElseIf Mid(r13, 2, 1) Like "[a-zA-Z]" Then
            r13 = Left(r13, 2) & " " & Right(r13, 1)
            Range("R13") = UCase(r13)
        Else
            r13 = UCase(Left(r13, 1)) & "'ly " & Right(r13, 1)
            Range("R13") = r13
        End If
    End If

Obviously with whichever cells it needs!

Worked perfectly.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,237
Members
448,555
Latest member
RobertJones1986

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