PDA

Click to See Complete Forum and Search --> : VB and Excel


aadetoro
Jul 11th, 1999, 05:13 PM
The following example uses a For Each...Next statement to iterate through each cell in a range named MyRange on Sheet1 of an active Microsoft Excel workbook. The variable c is a cell in the collection of cells contained in MyRange.

Sub ApplyFormat()
Const limit As Integer = 33
For Each c In I am having a liitle trouble with this program:
___________

Worksheets("Sheet1").Range("MyRange").Cells
If c.Value > limit Then
With c.Font
.Bold = True
.Italic = True
End With
End If
Next c
MsgBox "All done!"
End Sub
__________________

What I am trying to do is to change the contents of each cell in excel, but how do i declare each cell in a range so that i can loop through them.

This program does not work.

J Staniforth
Jul 11th, 1999, 06:51 PM
Try this;


Dim myCell As Excel.Range
Const limit As Integer = 33

For Each myCell In Worksheets("Sheet1").Range("A1:C10").Cells(1, 1)

' iterate through Cells - Row, Col

If myCell.Value > limit Then
With myCell.Font
.Bold = True
.Italic = True
End With
End If
Next myCell
MsgBox "All done!"

Regards,
John

[This message has been edited by J Staniforth (edited 07-12-1999).]