Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Macro to test characters with block of cells and change font

Hello,

I want to create a macro to test across a range of cells. In the below
attempt at the code, I assumed that the user has highlighted the desired
block. I want to test the contents of each cell, and to format superscript
only aphabetic characters (not numeric, and certainly not the entire cell).
The data I'm working with is primarily numeric, and any alphabetic characters
are a statistics notation. It would greatly save our graphics folks time to
have this macro that will superscript all alphabet characters while not
touching the numeric characters.

I cobbled together the below code based on code I found on F. David
McRitchie's webpage (http://www.mvps.org/dmcritchie/excel/join.htm). It kinda
works. But it only superscripts alpha characters the first cell in the
highlighted range. I need it to superscript for all cells in the highlighted
range.

Option Explicit
Sub SuperscriptLetters()
Dim cell As Range
Dim i As Integer

On Error Resume Next 'in case nothing found

For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
If Len(cell) 0 Then
For i = Len(cell) To 1 Step -1
If Mid(cell, i, 1) = "A" Then
With ActiveCell.Characters(Start:=i, Length:=1).Font
.Superscript = True
End With
End If
Next i
End If
Next cell

End Sub

Thank you in advance for any assistance!
Carolyn

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Macro to test characters with block of cells and change font

Option Explicit
Sub SuperscriptLetters()
Dim cell As Range
Dim i As Integer

On Error Resume Next 'in case nothing found

For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
If Len(cell) 0 Then
For i = Len(cell) To 1 Step -1
If Not IsNumeric(Mid(cell, i, 1)) Then
With cell.Characters(Start:=i, Length:=1).Font
.Superscript = True
End With
End If
Next i
End If
Next cell

End Sub

this superscripts everything that isn't a 1-9.

--
Regards,
Tom Ogilvy


"Carolyn" wrote:

Hello,

I want to create a macro to test across a range of cells. In the below
attempt at the code, I assumed that the user has highlighted the desired
block. I want to test the contents of each cell, and to format superscript
only aphabetic characters (not numeric, and certainly not the entire cell).
The data I'm working with is primarily numeric, and any alphabetic characters
are a statistics notation. It would greatly save our graphics folks time to
have this macro that will superscript all alphabet characters while not
touching the numeric characters.

I cobbled together the below code based on code I found on F. David
McRitchie's webpage (http://www.mvps.org/dmcritchie/excel/join.htm). It kinda
works. But it only superscripts alpha characters the first cell in the
highlighted range. I need it to superscript for all cells in the highlighted
range.

Option Explicit
Sub SuperscriptLetters()
Dim cell As Range
Dim i As Integer

On Error Resume Next 'in case nothing found

For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
If Len(cell) 0 Then
For i = Len(cell) To 1 Step -1
If Mid(cell, i, 1) = "A" Then
With ActiveCell.Characters(Start:=i, Length:=1).Font
.Superscript = True
End With
End If
Next i
End If
Next cell

End Sub

Thank you in advance for any assistance!
Carolyn

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Macro to test characters with block of cells and change font

Thank you very much for you assistance Tom. My graphics person is doing
cartwheels. Carolyn

"Tom Ogilvy" wrote:

Option Explicit
Sub SuperscriptLetters()
Dim cell As Range
Dim i As Integer

On Error Resume Next 'in case nothing found

For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
If Len(cell) 0 Then
For i = Len(cell) To 1 Step -1
If Not IsNumeric(Mid(cell, i, 1)) Then
With cell.Characters(Start:=i, Length:=1).Font
.Superscript = True
End With
End If
Next i
End If
Next cell

End Sub

this superscripts everything that isn't a 1-9.

--
Regards,
Tom Ogilvy


"Carolyn" wrote:

Hello,

I want to create a macro to test across a range of cells. In the below
attempt at the code, I assumed that the user has highlighted the desired
block. I want to test the contents of each cell, and to format superscript
only aphabetic characters (not numeric, and certainly not the entire cell).
The data I'm working with is primarily numeric, and any alphabetic characters
are a statistics notation. It would greatly save our graphics folks time to
have this macro that will superscript all alphabet characters while not
touching the numeric characters.

I cobbled together the below code based on code I found on F. David
McRitchie's webpage (http://www.mvps.org/dmcritchie/excel/join.htm). It kinda
works. But it only superscripts alpha characters the first cell in the
highlighted range. I need it to superscript for all cells in the highlighted
range.

Option Explicit
Sub SuperscriptLetters()
Dim cell As Range
Dim i As Integer

On Error Resume Next 'in case nothing found

For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
If Len(cell) 0 Then
For i = Len(cell) To 1 Step -1
If Mid(cell, i, 1) = "A" Then
With ActiveCell.Characters(Start:=i, Length:=1).Font
.Superscript = True
End With
End If
Next i
End If
Next cell

End Sub

Thank you in advance for any assistance!
Carolyn

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to test characters with block of cells and change font

Carolyn,

You did all the work - I just did some minor tweaking. Pat yourself on the
back <g

--
Regards,
Tom Ogilvy

"Carolyn" wrote in message
...
Thank you very much for you assistance Tom. My graphics person is doing
cartwheels. Carolyn

"Tom Ogilvy" wrote:

Option Explicit
Sub SuperscriptLetters()
Dim cell As Range
Dim i As Integer

On Error Resume Next 'in case nothing found

For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
If Len(cell) 0 Then
For i = Len(cell) To 1 Step -1
If Not IsNumeric(Mid(cell, i, 1)) Then
With cell.Characters(Start:=i, Length:=1).Font
.Superscript = True
End With
End If
Next i
End If
Next cell

End Sub

this superscripts everything that isn't a 1-9.

--
Regards,
Tom Ogilvy


"Carolyn" wrote:

Hello,

I want to create a macro to test across a range of cells. In the below
attempt at the code, I assumed that the user has highlighted the
desired
block. I want to test the contents of each cell, and to format
superscript
only aphabetic characters (not numeric, and certainly not the entire
cell).
The data I'm working with is primarily numeric, and any alphabetic
characters
are a statistics notation. It would greatly save our graphics folks
time to
have this macro that will superscript all alphabet characters while not
touching the numeric characters.

I cobbled together the below code based on code I found on F. David
McRitchie's webpage (http://www.mvps.org/dmcritchie/excel/join.htm). It
kinda
works. But it only superscripts alpha characters the first cell in the
highlighted range. I need it to superscript for all cells in the
highlighted
range.

Option Explicit
Sub SuperscriptLetters()
Dim cell As Range
Dim i As Integer

On Error Resume Next 'in case nothing found

For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
If Len(cell) 0 Then
For i = Len(cell) To 1 Step -1
If Mid(cell, i, 1) = "A" Then
With ActiveCell.Characters(Start:=i, Length:=1).Font
.Superscript = True
End With
End If
Next i
End If
Next cell

End Sub

Thank you in advance for any assistance!
Carolyn



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Macro to test characters with block of cells and change font

Here's the final macro that we've implemented. It could probably be
streamlined a bit more, but it's functional and meets our needs. Enjoy!
Carolyn

Option Explicit
Sub SuperscriptLetters()
Dim cell As Range
Dim i As Integer

On Error Resume Next 'in case nothing found

For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
If Len(cell) 0 Then
For i = Len(cell) To 1 Step -1
If Not (IsNumeric(Mid(cell, i, 1)) Or Mid(cell, i, 1) = "%" Or
Mid(cell, i, 1) = "$" Or Mid(cell, i, 1) = "." Or Mid(cell, i, 1) = ",") Then
With cell.Characters(Start:=i, Length:=1).Font
.Superscript = True
' .Bold = True
End With
End If
Next i
If Not (IsNumeric(cell)) Then
With cell.Characters.Font
' .Bold = True
.FontStyle = "Bold"
End With
End If
End If
Next cell

End Sub


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
Change relative to absolute references in a block of cells Giles Excel Discussion (Misc queries) 3 January 27th 09 02:19 PM
Change font in portions of cell with many characters (1000's) Barb Reinhardt Excel Discussion (Misc queries) 6 July 3rd 08 11:23 PM
reference, test and change cell font. feedscrn Excel Programming 3 May 23rd 06 12:40 AM
macro to white out (to change a font in selected cells) Tom Ogilvy Excel Programming 3 February 3rd 05 08:49 PM
a script/macro to copy a block of cells next to specified cells z.entropic[_2_] Excel Programming 8 November 14th 03 03:17 PM


All times are GMT +1. The time now is 10:54 PM.

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"