Does anybody know why this sheet code is ignored by Excel?


Posted by Joseph Was on May 16, 2001 9:54 AM

This is a sheet tab code which is intended to convert all text in a named range or defined columns to upper case. Modified it will convert all cells but fails with any attempt to licalize the change?

Sub UpperCase()
Dim rCells As Range
For Each col In Worksheets("Sheet1").Columns
If col.Column = 2 Or 3 Then
For Each rCells In Selection
rCells = UCase(rCells.Text)
Next col
End If
Next
End Sub

Posted by cpod on May 16, 2001 10:31 AM

If you are trying to limit to columns 2 and 3 then:

If col.Column = 2 Or col.Column = 3 Then

Posted by Joe Was on May 16, 2001 1:36 PM

Code continues to be ignored by Excel?

Added Column seggestion below. No change was noted?

Posted by Bertie on May 16, 2001 1:52 PM

Sub UpperCase()
Dim rCells As Range
If Selection.Column = 2 Or Selection.Column = 3 Then
For Each rCells In Selection
rCells = UCase(rCells.Text)
Next
End If
End Sub


Posted by Joe Was on May 16, 2001 2:08 PM

Sheet code is ignored by Excel even with this code change?

I tried your code change on a clean workbook, just encase my test workbook was contaminated and it failed. If I remove the column restriction it works for the whole sheet, as does other versions of this code, it just refuses to be restricted? : This is a sheet tab code which is intended to convert all text in a named range or defined columns to upper case. Modified it will convert all cells but fails with any attempt to licalize the change? : Sub UpperCase()


Posted by Bertie on May 16, 2001 2:36 PM

Re: Sheet code is ignored by Excel even with this code change?

It worked for me so I must be misunderstanding what you need.
In case the selection includes cells other than cells in columns B & C :-

Sub UpperCase()
Dim rCells As Range
If Not Intersect(Selection, Columns("B:C")) Is Nothing Then
For Each rCells In Intersect(Selection, Columns("B:C"))
rCells = UCase(rCells.Text)
Next
End If
End Sub I tried your code change on a clean workbook, just encase my test workbook was contaminated and it failed. If I remove the column restriction it works for the whole sheet, as does other versions of this code, it just refuses to be restricted?


Posted by Joe Was on May 16, 2001 3:30 PM

Bertie: Puzzled?

Added your code to a clean workbook. Added it to the sheet tab view code. If I type lower case letters in columns A through x, all the letters are lower case. Columns B and C should be converted to upper case?
I am using Excel 2000. I don't understand why I can change the whole sheet from lower case input to upper but not just a specified column? It worked for me so I must be misunderstanding what you need.


Posted by Bertie on May 16, 2001 4:55 PM

Re: Bertie: Puzzled?

If you put the macro in the Sheet module, it won't work if it is named Sub UpperCase().
Try the following :-

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rCells As Range
Application.EnableEvents = False
If Not Intersect(Target, Columns("B:C")) Is Nothing Then
For Each rCells In Intersect(Target, Columns("B:C"))
rCells = UCase(rCells.Text)
Next
End If
Application.EnableEvents = True
End Sub

Added your code to a clean workbook. Added it to the sheet tab view code. If I type lower case letters in columns A through x, all the letters are lower case. Columns B and C should be converted to upper case?




Posted by Joe Was on May 17, 2001 5:22 AM

Re: Bertie: I feel like a moron not knowing this. Thank you for helping.

Bertie,
Thank's for helping. I originally had a properly named private sub but got side-tracked with the Column code and changed it. I should have known the naming convention but did not. This board has been a life saver and is better than any text, thank's again. JSW If you put the macro in the Sheet module, it won't work if it is named Sub UpperCase().