lost in a loop

GS7CLW

Banned
Joined
Aug 10, 2010
Messages
168
Trying to thru the cells (F2 - F75) and select those with a number in the cell then center, bold and set a yellow BG for cells containing numbers

Code:
-----go thru the cells (F2 - F75) and select those with a number in the cell------
    Set rng = Range("F2:F75")
    For Each cell In rng
    '----------if the cell contains a number then------------
    If IsNumeric(c) Then
    '---center, bold and set a yellow BG for cells containing numbers-------
    ActiveCell.Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Selection.Font.Bold = True
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    End If
    Next

Any help appreciated
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try

Code:
'-----go thru the cells (F2 - F75) and select those with a number in the cell------
    Set Rng = Range("F2:F75")
    For Each cell In Rng
        '----------if the cell contains a number then------------
        If IsNumeric(c) Then
            '---center, bold and set a yellow BG for cells containing numbers-------
            With c.Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .Color = 65535
                .TintAndShade = 0
                .PatternTintAndShade = 0
            End With
            c.Font.Bold = True
            With c
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlBottom
            End With
        End If
    Next cell
 
Upvote 0
Give this a go, you were using the variable "Cell", but switched to "C" for the IsNumeric line.:

Code:
Public Sub GS7CLW()
Dim rng     As Range, _
    sRng    As Range
Set sRng = Range("F2:F75")
For Each rng In sRng
    '----------if the cell contains a number then------------
    If IsNumeric(rng) Then
    '---center, bold and set a yellow BG for cells containing numbers-------
        With rng
            .Interior.ColorIndex = 6
            .Font.Bold = True
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
        End With
    End If
Next rng
End Sub
 
Upvote 0
only problem I have now is it is centering bolding and bg yellow in the empty cells as well as those with a number it it....

Code:
Set rng = Range("F2:F75")
    For Each c In rng
        '----------if the cell contains a number then------------
        If IsNumeric(c) Then
            '---center, bold and set a yellow BG for cells containing numbers-------
            With c.Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .Color = 65535
                .TintAndShade = 0
                .PatternTintAndShade = 0
            End With
            c.Font.Bold = True
            With c
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlBottom
            End With
         End If
    Next c
 
Upvote 0
'---------------yes sir yes sir three bags full------------------;>))

THANKS everyone!!!!
cliff
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top