Results 1 to 2 of 2

For Each cell in range and If statement. Prevent code moving on until If met

Threaded View

coasterman For Each cell in range and If... 01-29-2012, 10:51 AM
coasterman Re: For Each cell in range... 01-29-2012, 11:28 AM
  1. #1
    Registered User
    Join Date
    04-22-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    59

    For Each cell in range and If statement. Prevent code moving on until If met

    Hi

    I have some modified code to check User entry into a varying number of cells and call up a MsgBox if any are empty.

    I must have the placement of the what to do line if condition not met in the wrong place as whilst the code catches the missing entries once warned it moves and calls the next sub routine.

    As you will see I want the code to stop and return user to P12 which is the general area of where these cells are located.

    Hopefully this is a simple fix and just me being dense.

    Many thanks

    Private Sub cmdCarePaste_Click()
    Dim i As Integer
    Dim r As Range
    
    i = Sheets("CareTbl28Calx").cbWsPeriodCount.Value + 11
    Set r = Range("P12:P" & i)
    For Each cell In r
            If Not IsNumeric(cell) Or cell.Value = vbNullString Then
                MsgBox ("Certain periods have no annual care amounts entered"), vbCritical, "Annual amount warning"
                Sheets("CareTbl28Calx").Range("P12").Activate
                Exit Sub
                Cancel = True
                Exit For
            End If
        Next
    
    Call CareTbl28CalxcompPaste_NextEmptyRow
        
    ' and so on
    Last edited by coasterman; 01-29-2012 at 11:28 AM.

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