Results 1 to 2 of 2

Thread: VB and Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Posts
    3

    Post

    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.

  2. #2
    Addicted Member
    Join Date
    Jan 1999
    Posts
    165

    Post

    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).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width