Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help modify macro
I got this code from this NG, I do not remember the authors name, but thanks
any how because it works quite well. I am failing to find a way to make this macro ignore all characters within brackets "()". Any help is be appreciated. '====== 'Change Text to Upper Case or Proper Case. See Also: 'Force Upper Case/Proper Case 'Excel has 2 built in functions for converting text to 'either UPPER CASE or Proper Case. The 2 functions that 'do this are shown below; '=UPPER(A1) '=PROPER(A1) 'These Excel functions work well when referring to cells 'that house the text. However, there are many instances 'when using the Worksheet Function approach is not practical. 'The Excel macro code below can be used to change existing 'text to either UPPER CASE or Proper Case. If you run the 'macro with only a single cell selected it will work on the 'entire Worksheet. If you run the macro with more than 1 'cell selected it will work on only your selection. 'The other settings that the StrConv Function take are 'shown below. See the Excel VBA help for specifics. Sub ConvertCase() Dim rAcells As Range, rLoopCells As Range Dim lReply As Long 'Set variable to needed cells If Selection.Cells.Count = 1 Then Set rAcells = ActiveSheet.UsedRange Else Set rAcells = Selection End If On Error Resume Next 'In case of NO text constants. 'Set variable to all text constants Set rAcells = rAcells.SpecialCells(xlCellTypeConstants, xlTextValues) If rAcells Is Nothing Then MsgBox "Could not find any text." On Error GoTo 0 Exit Sub End If lReply = MsgBox("Select 'Yes' for UPPER CASE or 'No' for Proper Case.", _ vbYesNoCancel, "OzGrid.com") If lReply = vbCancel Then Exit Sub If lReply = vbYes Then ' Convert to Upper Case For Each rLoopCells In rAcells rLoopCells = StrConv(rLoopCells, vbUpperCase) Next rLoopCells Else ' Convert to Proper Case For Each rLoopCells In rAcells rLoopCells = StrConv(rLoopCells, vbProperCase) Next rLoopCells End If End Sub '====== -- Regards VBA.Newb.Confused XP Pro Office 2007 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help modify macro
The macro uses two (2) functions ... it either uses UPPER or Proper to change
the case. These functions will NOT address your concern. As in most cases, code could be written, but it would be a lil' bigger job than 'modifing' this macro. Sorry. "Rick S." wrote: I got this code from this NG, I do not remember the authors name, but thanks any how because it works quite well. I am failing to find a way to make this macro ignore all characters within brackets "()". Any help is be appreciated. '====== 'Change Text to Upper Case or Proper Case. See Also: 'Force Upper Case/Proper Case 'Excel has 2 built in functions for converting text to 'either UPPER CASE or Proper Case. The 2 functions that 'do this are shown below; '=UPPER(A1) '=PROPER(A1) 'These Excel functions work well when referring to cells 'that house the text. However, there are many instances 'when using the Worksheet Function approach is not practical. 'The Excel macro code below can be used to change existing 'text to either UPPER CASE or Proper Case. If you run the 'macro with only a single cell selected it will work on the 'entire Worksheet. If you run the macro with more than 1 'cell selected it will work on only your selection. 'The other settings that the StrConv Function take are 'shown below. See the Excel VBA help for specifics. Sub ConvertCase() Dim rAcells As Range, rLoopCells As Range Dim lReply As Long 'Set variable to needed cells If Selection.Cells.Count = 1 Then Set rAcells = ActiveSheet.UsedRange Else Set rAcells = Selection End If On Error Resume Next 'In case of NO text constants. 'Set variable to all text constants Set rAcells = rAcells.SpecialCells(xlCellTypeConstants, xlTextValues) If rAcells Is Nothing Then MsgBox "Could not find any text." On Error GoTo 0 Exit Sub End If lReply = MsgBox("Select 'Yes' for UPPER CASE or 'No' for Proper Case.", _ vbYesNoCancel, "OzGrid.com") If lReply = vbCancel Then Exit Sub If lReply = vbYes Then ' Convert to Upper Case For Each rLoopCells In rAcells rLoopCells = StrConv(rLoopCells, vbUpperCase) Next rLoopCells Else ' Convert to Proper Case For Each rLoopCells In rAcells rLoopCells = StrConv(rLoopCells, vbProperCase) Next rLoopCells End If End Sub '====== -- Regards VBA.Newb.Confused XP Pro Office 2007 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help modify macro
I was affraid of that, as I have failed miserably.
Thanks for your input. -- Regards VBA.Newb.Confused XP Pro Office 2007 "ND Pard" wrote: The macro uses two (2) functions ... it either uses UPPER or Proper to change the case. These functions will NOT address your concern. As in most cases, code could be written, but it would be a lil' bigger job than 'modifing' this macro. Sorry. "Rick S." wrote: I got this code from this NG, I do not remember the authors name, but thanks any how because it works quite well. I am failing to find a way to make this macro ignore all characters within brackets "()". Any help is be appreciated. '====== 'Change Text to Upper Case or Proper Case. See Also: 'Force Upper Case/Proper Case 'Excel has 2 built in functions for converting text to 'either UPPER CASE or Proper Case. The 2 functions that 'do this are shown below; '=UPPER(A1) '=PROPER(A1) 'These Excel functions work well when referring to cells 'that house the text. However, there are many instances 'when using the Worksheet Function approach is not practical. 'The Excel macro code below can be used to change existing 'text to either UPPER CASE or Proper Case. If you run the 'macro with only a single cell selected it will work on the 'entire Worksheet. If you run the macro with more than 1 'cell selected it will work on only your selection. 'The other settings that the StrConv Function take are 'shown below. See the Excel VBA help for specifics. Sub ConvertCase() Dim rAcells As Range, rLoopCells As Range Dim lReply As Long 'Set variable to needed cells If Selection.Cells.Count = 1 Then Set rAcells = ActiveSheet.UsedRange Else Set rAcells = Selection End If On Error Resume Next 'In case of NO text constants. 'Set variable to all text constants Set rAcells = rAcells.SpecialCells(xlCellTypeConstants, xlTextValues) If rAcells Is Nothing Then MsgBox "Could not find any text." On Error GoTo 0 Exit Sub End If lReply = MsgBox("Select 'Yes' for UPPER CASE or 'No' for Proper Case.", _ vbYesNoCancel, "OzGrid.com") If lReply = vbCancel Then Exit Sub If lReply = vbYes Then ' Convert to Upper Case For Each rLoopCells In rAcells rLoopCells = StrConv(rLoopCells, vbUpperCase) Next rLoopCells Else ' Convert to Proper Case For Each rLoopCells In rAcells rLoopCells = StrConv(rLoopCells, vbProperCase) Next rLoopCells End If End Sub '====== -- Regards VBA.Newb.Confused XP Pro Office 2007 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help modify macro
I'm afraid ND Pard was wrong... the modification to make that macro ignore
text inside of parentheses is relatively easy to do. Sub ConvertCase() Dim rAcells As Range, Dim rLoopCells As Range Dim X As Long Dim lReply As Long Dim TextLine As String Dim Parsed() As String 'Set variable to needed cells If Selection.Cells.Count = 1 Then Set rAcells = ActiveSheet.UsedRange Else Set rAcells = Selection End If On Error Resume Next 'In case of NO text constants. 'Set variable to all text constants Set rAcells = rAcells.SpecialCells(xlCellTypeConstants, xlTextValues) If rAcells Is Nothing Then MsgBox "Could not find any text." On Error GoTo 0 Exit Sub End If lReply = MsgBox("Select 'Yes' for UPPER CASE; 'No' for Proper Case.", _ vbYesNoCancel, "OzGrid.com") If lReply = vbCancel Then Exit Sub For Each rLoopCells In rAcells TextLine = Replace(rLoopCells, ")", "()") Parsed = Split(TextLine, "(") For X = 0 To UBound(Parsed) Step 2 Parsed(X) = StrConv(Parsed(X), IIf(lReply = vbYes, _ vbUpperCase, vbProperCase)) Next rLoopCells = Replace(Join(Parsed, "("), "()", ")") Next End Sub Rick "Rick S." wrote in message ... I was affraid of that, as I have failed miserably. Thanks for your input. -- Regards VBA.Newb.Confused XP Pro Office 2007 "ND Pard" wrote: The macro uses two (2) functions ... it either uses UPPER or Proper to change the case. These functions will NOT address your concern. As in most cases, code could be written, but it would be a lil' bigger job than 'modifing' this macro. Sorry. "Rick S." wrote: I got this code from this NG, I do not remember the authors name, but thanks any how because it works quite well. I am failing to find a way to make this macro ignore all characters within brackets "()". Any help is be appreciated. '====== 'Change Text to Upper Case or Proper Case. See Also: 'Force Upper Case/Proper Case 'Excel has 2 built in functions for converting text to 'either UPPER CASE or Proper Case. The 2 functions that 'do this are shown below; '=UPPER(A1) '=PROPER(A1) 'These Excel functions work well when referring to cells 'that house the text. However, there are many instances 'when using the Worksheet Function approach is not practical. 'The Excel macro code below can be used to change existing 'text to either UPPER CASE or Proper Case. If you run the 'macro with only a single cell selected it will work on the 'entire Worksheet. If you run the macro with more than 1 'cell selected it will work on only your selection. 'The other settings that the StrConv Function take are 'shown below. See the Excel VBA help for specifics. Sub ConvertCase() Dim rAcells As Range, rLoopCells As Range Dim lReply As Long 'Set variable to needed cells If Selection.Cells.Count = 1 Then Set rAcells = ActiveSheet.UsedRange Else Set rAcells = Selection End If On Error Resume Next 'In case of NO text constants. 'Set variable to all text constants Set rAcells = rAcells.SpecialCells(xlCellTypeConstants, xlTextValues) If rAcells Is Nothing Then MsgBox "Could not find any text." On Error GoTo 0 Exit Sub End If lReply = MsgBox("Select 'Yes' for UPPER CASE or 'No' for Proper Case.", _ vbYesNoCancel, "OzGrid.com") If lReply = vbCancel Then Exit Sub If lReply = vbYes Then ' Convert to Upper Case For Each rLoopCells In rAcells rLoopCells = StrConv(rLoopCells, vbUpperCase) Next rLoopCells Else ' Convert to Proper Case For Each rLoopCells In rAcells rLoopCells = StrConv(rLoopCells, vbProperCase) Next rLoopCells End If End Sub '====== -- Regards VBA.Newb.Confused XP Pro Office 2007 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help modify macro
I do not understand how you did that, but it works great!!!
Thank you!!! -- Regards VBA.Newb.Confused XP Pro Office 2007 "Rick Rothstein (MVP - VB)" wrote: I'm afraid ND Pard was wrong... the modification to make that macro ignore text inside of parentheses is relatively easy to do. Sub ConvertCase() Dim rAcells As Range, Dim rLoopCells As Range Dim X As Long Dim lReply As Long Dim TextLine As String Dim Parsed() As String 'Set variable to needed cells If Selection.Cells.Count = 1 Then Set rAcells = ActiveSheet.UsedRange Else Set rAcells = Selection End If On Error Resume Next 'In case of NO text constants. 'Set variable to all text constants Set rAcells = rAcells.SpecialCells(xlCellTypeConstants, xlTextValues) If rAcells Is Nothing Then MsgBox "Could not find any text." On Error GoTo 0 Exit Sub End If lReply = MsgBox("Select 'Yes' for UPPER CASE; 'No' for Proper Case.", _ vbYesNoCancel, "OzGrid.com") If lReply = vbCancel Then Exit Sub For Each rLoopCells In rAcells TextLine = Replace(rLoopCells, ")", "()") Parsed = Split(TextLine, "(") For X = 0 To UBound(Parsed) Step 2 Parsed(X) = StrConv(Parsed(X), IIf(lReply = vbYes, _ vbUpperCase, vbProperCase)) Next rLoopCells = Replace(Join(Parsed, "("), "()", ")") Next End Sub Rick "Rick S." wrote in message ... I was affraid of that, as I have failed miserably. Thanks for your input. -- Regards VBA.Newb.Confused XP Pro Office 2007 "ND Pard" wrote: The macro uses two (2) functions ... it either uses UPPER or Proper to change the case. These functions will NOT address your concern. As in most cases, code could be written, but it would be a lil' bigger job than 'modifing' this macro. Sorry. "Rick S." wrote: I got this code from this NG, I do not remember the authors name, but thanks any how because it works quite well. I am failing to find a way to make this macro ignore all characters within brackets "()". Any help is be appreciated. '====== 'Change Text to Upper Case or Proper Case. See Also: 'Force Upper Case/Proper Case 'Excel has 2 built in functions for converting text to 'either UPPER CASE or Proper Case. The 2 functions that 'do this are shown below; '=UPPER(A1) '=PROPER(A1) 'These Excel functions work well when referring to cells 'that house the text. However, there are many instances 'when using the Worksheet Function approach is not practical. 'The Excel macro code below can be used to change existing 'text to either UPPER CASE or Proper Case. If you run the 'macro with only a single cell selected it will work on the 'entire Worksheet. If you run the macro with more than 1 'cell selected it will work on only your selection. 'The other settings that the StrConv Function take are 'shown below. See the Excel VBA help for specifics. Sub ConvertCase() Dim rAcells As Range, rLoopCells As Range Dim lReply As Long 'Set variable to needed cells If Selection.Cells.Count = 1 Then Set rAcells = ActiveSheet.UsedRange Else Set rAcells = Selection End If On Error Resume Next 'In case of NO text constants. 'Set variable to all text constants Set rAcells = rAcells.SpecialCells(xlCellTypeConstants, xlTextValues) If rAcells Is Nothing Then MsgBox "Could not find any text." On Error GoTo 0 Exit Sub End If lReply = MsgBox("Select 'Yes' for UPPER CASE or 'No' for Proper Case.", _ vbYesNoCancel, "OzGrid.com") If lReply = vbCancel Then Exit Sub If lReply = vbYes Then ' Convert to Upper Case For Each rLoopCells In rAcells rLoopCells = StrConv(rLoopCells, vbUpperCase) Next rLoopCells Else ' Convert to Proper Case For Each rLoopCells In rAcells rLoopCells = StrConv(rLoopCells, vbProperCase) Next rLoopCells End If End Sub '====== -- Regards VBA.Newb.Confused XP Pro Office 2007 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help modify macro
I do not understand how you did that,
If you are familiar with VBA, do you want an explanation? but it works great!!! I'm glad it worked out for you (I was a little worried that ND Pard's response might have kept you from looking back into this thread in order to see it). Rick |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Modify A Macro | Excel Worksheet Functions | |||
Modify a Macro | Excel Worksheet Functions | |||
Modify Macro | Excel Programming | |||
Modify a macro | Excel Programming | |||
Help to modify macro please | Excel Programming |