Macro DoSomething in every cell of my selected range

S

Snoopy

Hey Guys
I have a selection of cells where I have to do some special formatting
- same procedure in every cell.
The selection will be like Range("A1:H1") or other continious cells as
range - dynamicly chosen before running macro

I have this macro "Formatting" to process (format) values in every
cell of my selection. This sub-macro is ok - but I am not able to make
a macro running through all cells in the selection (and start the sub-
macro: "Formatting" in all selected cells), and stop when all cells
are formatted.

Example:
In every cell of Range("H1:M1) I want this macro (below) to format the
cells:

Sub Formatting()

With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Arial Narrow"
.FontStyle = "Normal"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=2, Length:=2).Font
.Name = "Arial Narrow"
.FontStyle = "Normal"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = True
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
End Sub

I would really wish you would help me on this one - as many times
before
Regards Snoopy
 
D

Don Guillett

A simple loop. Also, I'm sure you can eliminate most of the items by
deleting or commenting out.

Sub FormattingLoop()
for each c in selection
With c.Characters(Start:=1, Length:=1).Font
.Name = "Arial Narrow"
.FontStyle = "Normal"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With c.Characters(Start:=2, Length:=2).Font
.Name = "Arial Narrow"
.FontStyle = "Normal"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = True
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
next c
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top