specific values to caps???

LlebKcir

Board Regular
Joined
Oct 8, 2018
Messages
219
To keep the look clean and simple on a few spreadsheets the desire is to have y, yes, n, no, na, n/a inputs from the user displayed as capital letters. looking around i found some vba code that will kind of do what i am after, but the way i typed it up, it cycles through all of the options in the code and does not let you clear the cell. once data is in the cell, it is there for good until you disable the macro.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim A1 As Range
    Set A1 = Range("B:G")
    If Not Intersect(Target, A1) Is Nothing Then
        Application.EnableEvents = False
            Target.Value = UCase("y")
            Target.Value = UCase("yes")
            Target.Value = UCase("n")
            Target.Value = UCase("no")
            Target.Value = UCase("n/a")
            Target.Value = UCase("na")
        Application.EnableEvents = True
    End If
End Sub

it is actually kind of funny to watch. please help me help you so i can learn.

Thank you.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this instead

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range
  
  Set Changed = Intersect(Target, Columns("B:G"))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    For Each c In Changed
      Select Case LCase(c.Value)
        Case "y", "yes", "n", "no", "na", "n/a"
          c.Value = UCase(c.Value)
      End Select
    Next c
    Application.EnableEvents = True
  End If
End Sub
 
Upvote 0
Try this instead

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range
  
  Set Changed = Intersect(Target, Columns("B:G"))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    For Each c In Changed
      Select Case LCase(c.Value)
        Case "y", "yes", "n", "no", "na", "n/a"
          c.Value = UCase(c.Value)
      End Select
    Next c
    Application.EnableEvents = True
  End If
End Sub

Peter, thank you that works great. I never thought of using the case logic inside of that loop.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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