+ Reply to Thread
Results 1 to 2 of 2

For Each Statement not working as expected

Hybrid View

Guest For Each Statement not... 11-02-2005, 06:20 PM
Guest Re: For Each Statement not... 11-02-2005, 06:20 PM
  1. #1
    Jacqui
    Guest

    For Each Statement not working as expected

    I have the following syntax using a For Each statement to check column c and
    if this contains a value which is NOT in bold text, the code checks columns
    K:N and if these cells are empty the user receives an error message via a
    msgbox. However if I deliberately create known errors on the sheet the
    syntax is finding the first occurance only and ignoring the others. How can
    I fix please, the VBA is below

    Thanks
    Jacqui

    Sub Qualifiers_Check()

    Set wks = ActiveWorkbook.Worksheets("Part B - Coding Details")

    With wks

    Set myRng = .Range("c20", .Cells(.Rows.Count, "c").End(xlUp))

    Set myRng = myRng.Resize(myRng.Count - 1)

    For Each myCell In myRng.Cells
    If IsEmpty(myCell.Value) = False And Not myCell.Font.Bold Then
    Set myRngToCheck = .Cells(myCell.Row, "k").Resize(1, 4)
    If Application.CountA(myRngToCheck) <> myRngToCheck.Cells.Count
    Then
    Beep
    MsgBox "You have not supplied all the relevant information
    for this Segment type in Row " _
    & myCell.Row & " on the Coding Details Sheet - PLEASE ENTER
    ALL DETAILS"

    End If
    End If
    Next myCell

    End With

    End Sub



  2. #2
    Carlos
    Guest

    Re: For Each Statement not working as expected

    Hi Jacqui

    in line -Set myRngToCheck = .Cells(myCell.Row, "k").Resize(1, 4)- missing
    object

    Try -Set myRngToCheck = ActiveSheet.Cells(myCell.Row, "k").Resize(1, 4)-

    Carlos
    "Jacqui" <Jacqui@discussions.microsoft.com> wrote in message
    news:72F7FC6B-702E-4BD8-945B-D6AABA15FD55@microsoft.com...
    >I have the following syntax using a For Each statement to check column c
    >and
    > if this contains a value which is NOT in bold text, the code checks
    > columns
    > K:N and if these cells are empty the user receives an error message via a
    > msgbox. However if I deliberately create known errors on the sheet the
    > syntax is finding the first occurance only and ignoring the others. How
    > can
    > I fix please, the VBA is below
    >
    > Thanks
    > Jacqui
    >
    > Sub Qualifiers_Check()
    >
    > Set wks = ActiveWorkbook.Worksheets("Part B - Coding Details")
    >
    > With wks
    >
    > Set myRng = .Range("c20", .Cells(.Rows.Count, "c").End(xlUp))
    >
    > Set myRng = myRng.Resize(myRng.Count - 1)
    >
    > For Each myCell In myRng.Cells
    > If IsEmpty(myCell.Value) = False And Not myCell.Font.Bold Then
    > Set myRngToCheck = .Cells(myCell.Row, "k").Resize(1, 4)
    > If Application.CountA(myRngToCheck) <> myRngToCheck.Cells.Count
    > Then
    > Beep
    > MsgBox "You have not supplied all the relevant information
    > for this Segment type in Row " _
    > & myCell.Row & " on the Coding Details Sheet - PLEASE
    > ENTER
    > ALL DETAILS"
    >
    > End If
    > End If
    > Next myCell
    >
    > End With
    >
    > End Sub
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1