Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 49
Default Automatically change case is Excel when typed

I have two worksheets that I need to automatically change the case to Upper
regardless of how it was typed in the first place.
In one worksheet, the range is Column C and in the second worksheet, the
range is Column B.
From looking at various entries from other people, I have a code (see below)
to use which works on one sheet, but not on the other. I'm not sure if it is
because I already have a code to change the colour of cells depending on
their criteria.
Please help.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Automatically change case is Excel when typed

You will need two separate macros, one for each sheet.
--
Gary''s Student - gsnu200766


"harwookf" wrote:

I have two worksheets that I need to automatically change the case to Upper
regardless of how it was typed in the first place.
In one worksheet, the range is Column C and in the second worksheet, the
range is Column B.
From looking at various entries from other people, I have a code (see below)
to use which works on one sheet, but not on the other. I'm not sure if it is
because I already have a code to change the colour of cells depending on
their criteria.
Please help.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 49
Default Automatically change case is Excel when typed

I have the same macro in both worksheets, except one has B:B and the other
has C:C, but it still doesn't work on the sheet that already has another
macro to change the colour of the cells.

Any more ideas?


"Gary''s Student" wrote:

You will need two separate macros, one for each sheet.
--
Gary''s Student - gsnu200766


"harwookf" wrote:

I have two worksheets that I need to automatically change the case to Upper
regardless of how it was typed in the first place.
In one worksheet, the range is Column C and in the second worksheet, the
range is Column B.
From looking at various entries from other people, I have a code (see below)
to use which works on one sheet, but not on the other. I'm not sure if it is
because I already have a code to change the colour of cells depending on
their criteria.
Please help.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 49
Default Automatically change case is Excel when typed

The error message is saying Compile Error: Ambiguous name detected:
Worksheet_Change


"harwookf" wrote:

I have two worksheets that I need to automatically change the case to Upper
regardless of how it was typed in the first place.
In one worksheet, the range is Column C and in the second worksheet, the
range is Column B.
From looking at various entries from other people, I have a code (see below)
to use which works on one sheet, but not on the other. I'm not sure if it is
because I already have a code to change the colour of cells depending on
their criteria.
Please help.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Automatically change case is Excel when typed

Make sure that you have one and only one sub in each worksheet code area.


You will need to combine the color one with the new one.
--
Gary''s Student - gsnu200766


"harwookf" wrote:

The error message is saying Compile Error: Ambiguous name detected:
Worksheet_Change


"harwookf" wrote:

I have two worksheets that I need to automatically change the case to Upper
regardless of how it was typed in the first place.
In one worksheet, the range is Column C and in the second worksheet, the
range is Column B.
From looking at various entries from other people, I have a code (see below)
to use which works on one sheet, but not on the other. I'm not sure if it is
because I already have a code to change the colour of cells depending on
their criteria.
Please help.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub




  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 49
Default Automatically change case is Excel when typed

I'm not quite sure how to join them. This is the macro I have for the colour
part.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rArea As Range
Dim rCell As Range
Dim nColor As Long
Set Target = Intersect(Target, Range("E:E"))
If Not Target Is Nothing Then
For Each rArea In Target
For Each rCell In rArea
Select Case rCell.Value
Case 0, 100
nColor = RGB(255, 0, 0)
Case 30
nColor = RGB(23, 178, 233)
Case 60
nColor = RGB(245, 200, 11)
Case 90
nColor = RGB(0, 255, 0)
Case Else
nColor = RGB(255, 255, 255)
End Select
If Not nColor = -1 Then
rCell.Offset(0, -4).Interior.Color = nColor
Else
rCell.Offset(0, -4).Interior.ColorIndex = _
xlColorIndexNone
End If

Next rCell
Next rArea
End If
End Sub

I've tried removing the End Sub and the first line of the Upper case macro,
but this doesn't work. It is probably something very simple that I have not
done correctly.


"Gary''s Student" wrote:

Make sure that you have one and only one sub in each worksheet code area.


You will need to combine the color one with the new one.
--
Gary''s Student - gsnu200766


"harwookf" wrote:

The error message is saying Compile Error: Ambiguous name detected:
Worksheet_Change


"harwookf" wrote:

I have two worksheets that I need to automatically change the case to Upper
regardless of how it was typed in the first place.
In one worksheet, the range is Column C and in the second worksheet, the
range is Column B.
From looking at various entries from other people, I have a code (see below)
to use which works on one sheet, but not on the other. I'm not sure if it is
because I already have a code to change the colour of cells depending on
their criteria.
Please help.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Automatically change case is Excel when typed

Not vigorously tested:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rArea As Range
Dim rCell As Range
Dim nColor As Long
Dim Rng1 As Range
Dim Rng2 As Range

Set Rng1 = Intersect(Target, Me.Range("E:E"))
Set Rng2 = Intersect(Target, Me.Range("b:b"))

On Error GoTo ws_exit

'do the column E stuff
If Not (Rng1 Is Nothing) Then
For Each rCell In Rng1.Cells
Select Case rCell.Value
Case 0, 100
nColor = RGB(255, 0, 0)
Case 30
nColor = RGB(23, 178, 233)
Case 60
nColor = RGB(245, 200, 11)
Case 90
nColor = RGB(0, 255, 0)
Case Else
nColor = RGB(255, 255, 255)
End Select

If Not nColor = -1 Then
rCell.Offset(0, -4).Interior.Color = nColor
Else
rCell.Offset(0, -4).Interior.ColorIndex = _
xlColorIndexNone
End If

Next rCell
End If

'do the column B stuff
If Not (Rng2 Is Nothing) Then
Application.EnableEvents = False
For Each rCell In Rng2.Cells
With rCell
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
Next rCell
End If

ws_exit:
Application.EnableEvents = True

End Sub


harwookf wrote:

I have two worksheets that I need to automatically change the case to Upper
regardless of how it was typed in the first place.
In one worksheet, the range is Column C and in the second worksheet, the
range is Column B.
From looking at various entries from other people, I have a code (see below)
to use which works on one sheet, but not on the other. I'm not sure if it is
because I already have a code to change the colour of cells depending on
their criteria.
Please help.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,344
Default Automatically change case is Excel when typed

Hi,

I tested your original code and it work fine although you could shorten it to

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "C:C" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Range(WS_RANGE)) Is Nothing Then
If Not Target.HasFormula Then
Target = UCase(Target)
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

--
Thanks,
Shane Devenshire


"harwookf" wrote:

I have two worksheets that I need to automatically change the case to Upper
regardless of how it was typed in the first place.
In one worksheet, the range is Column C and in the second worksheet, the
range is Column B.
From looking at various entries from other people, I have a code (see below)
to use which works on one sheet, but not on the other. I'm not sure if it is
because I already have a code to change the colour of cells depending on
their criteria.
Please help.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 49
Default Automatically change case is Excel when typed

Many thanks, this has worked perfectly.

Cheers


"Dave Peterson" wrote:

Not vigorously tested:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rArea As Range
Dim rCell As Range
Dim nColor As Long
Dim Rng1 As Range
Dim Rng2 As Range

Set Rng1 = Intersect(Target, Me.Range("E:E"))
Set Rng2 = Intersect(Target, Me.Range("b:b"))

On Error GoTo ws_exit

'do the column E stuff
If Not (Rng1 Is Nothing) Then
For Each rCell In Rng1.Cells
Select Case rCell.Value
Case 0, 100
nColor = RGB(255, 0, 0)
Case 30
nColor = RGB(23, 178, 233)
Case 60
nColor = RGB(245, 200, 11)
Case 90
nColor = RGB(0, 255, 0)
Case Else
nColor = RGB(255, 255, 255)
End Select

If Not nColor = -1 Then
rCell.Offset(0, -4).Interior.Color = nColor
Else
rCell.Offset(0, -4).Interior.ColorIndex = _
xlColorIndexNone
End If

Next rCell
End If

'do the column B stuff
If Not (Rng2 Is Nothing) Then
Application.EnableEvents = False
For Each rCell In Rng2.Cells
With rCell
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
Next rCell
End If

ws_exit:
Application.EnableEvents = True

End Sub


harwookf wrote:

I have two worksheets that I need to automatically change the case to Upper
regardless of how it was typed in the first place.
In one worksheet, the range is Column C and in the second worksheet, the
range is Column B.
From looking at various entries from other people, I have a code (see below)
to use which works on one sheet, but not on the other. I'm not sure if it is
because I already have a code to change the colour of cells depending on
their criteria.
Please help.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change mixed case to upper case in Excel for all cells WordAlone Network Excel Discussion (Misc queries) 7 May 30th 07 06:53 AM
Change the text from lower case to upper case in an Excel work boo dave01968 Excel Discussion (Misc queries) 2 December 9th 05 10:09 AM
automatically change text case on entry John Davies Excel Discussion (Misc queries) 2 July 15th 05 09:42 AM
How do I change a column in Excel from upper case to lower case? Debbie Kennedy Excel Worksheet Functions 3 May 2nd 05 07:57 PM
change typed text to upper case CT Cameron Excel Discussion (Misc queries) 2 November 30th 04 02:07 AM


All times are GMT +1. The time now is 04:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"