+ Reply to Thread
Results 1 to 20 of 20

Looks at 2 fields and If one doesnt contain certain characters then set to 0.

Hybrid View

  1. #1
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Looks at 2 fields and If one doesnt contain certain characters then set to 0.

    I can see a couple of issues with the code posted:

    -The line in red is missing "or not" between "Range("K" & i) = 0" and "Range("K" & i) = 1".
    -Your end if statements do not match up to the if statements correctly, your code should have this format:
    for a = 1 to lrow
       if Range("I" & i).value like "BPS*" then
          if not Range("K" & i) = 0 or not Range("K"& i) =1 or not Range("K" & i) = 2 then 
             'do this code
          end if
       elseif Range("I" & i).value like "CAH*" then
          'and so on
       end if
    next

  2. #2
    Registered User
    Join Date
    03-08-2013
    Location
    Derbyshire
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Looks at 2 fields and If one doesnt contain certain characters then set to 0.

    Whops you were right about the or not bit. Ive corrected that. I cant quite see the other issue your taking about based on the small example compared to the one Ive got

    Ive currently got an error at the end on Next i (Next without for is the error)

    Is it possible to show where I have gone wrong based on the example below? Im basically, in a field and checking one field against the other for each group. When Ive either set it to 0 or found no problems I continue to the next field until I have no rows left

    
    For i = 7 To lrow
        'If Job_Family_Desc = AA use the AA range as a validation list
                If .Range("I" & i).Value Like "BPS*" Then
                If Not Range("K" & i) = 0 Or Not Range("K" & i) = 1 Or Not Range("K" & i) = 2 Or Not Range("K" & i) = 3 Or Not Range("K7") = 4 Or Not Range("K" & i) = 5 Or Not Range("K" & i) = 6 Or Not Range("K" & i) = 7 Or Not Range("K" & i) = 8 Or Not Range("K" & i) = 9 Or Not Range("K" & i) = 10 Or Not Range("K" & i) = 11 Or Not Range("K" & i) = 12 Or Not Range("K" & i) = 13 Or Not Range("K" & i) = 14 Then
                Range("K" & i) = 0
                        
                        'And when you have done it you want to go down to the next row
                        Selection.Offset(1, 0).Select
    
                ElseIf .Range("I" & i).Value Like "CAH*" Then
                If Not Range("K" & i) = 0 Or Not Range("K" & i) = 6 Or Not Range("K" & i) = 7 Or Not Range("K" & i) = 8 Or Not Range("K7") = 9 Or Not Range("K" & i) = 10 Or Not Range("K" & i) = 11 Or Not Range("K" & i) = 12 Or Not Range("K" & i) = 13 Or Not Range("K" & i) = 14 Then
                Range("K" & i) = 0
                        
                        'And when you have done it you want to go down to the next row
                        Selection.Offset(1, 0).Select
                        
                ElseIf .Range("I" & i).Value Like "CAM*" Then
                If Not Range("K" & i) = 0 Or Not Range("K" & i) = 1 Or Not Range("K" & i) = 2 Or Not Range("K" & i) = 3 Or Not Range("K7") = 4 Or Not Range("K" & i) = 5 Or Not Range("K" & i) = 6 Or Not Range("K" & i) = 7 Or Not Range("K" & i) = 8 Or Not Range("K" & i) = 9 Or Not Range("K" & i) = 10 Or Not Range("K" & i) = 11 Then Range("K" & i) = 0
    
                   
                        'And when you have done it you want to go down to the next row
                        Selection.Offset(1, 0).Select
                        
                ElseIf .Range("I" & i).Value Like "CAT*" Then
                If Not Range("K7") = 0 Or Not Range("K" & i) = 1 Or Not Range("K" & i) = 2 Or Not Range("K7") = 3 Or Not Range("K7") = 4 Or Not Range("K" & i) = 5 Or Not Range("K" & i) = 6 Or Not Range("K" & i) = 7 Or Not Range("K" & i) = 8 Or Not Range("K" & i) = 9 Or Not Range("K" & i) = 10 Or Not Range("K" & i) = 11 Or Not Range("K" & i) = 12 Or Not Range("K" & i) = 13 Then
                Range("K" & i) = 0
    
                   
                        'And when you have done it you want to go down to the next row
                        Selection.Offset(1, 0).Select
                        
                ElseIf .Range("I" & i).Value Like "SCI*" Then
                If Not Range("K" & i) = 0 Or Not Range("K7") = 4 Or Not Range("K" & i) = 5 Or Not Range("K" & i) = 6 Or Not Range("K" & i) = 7 Or Not Range("K" & i) = 8 Or Not Range("K" & i) = 9 Or Not Range("K" & i) = 10 Or Not Range("K" & i) = 11 Or Not Range("K" & i) = 12 Or Not Range("K" & i) = 13 Or Not Range("K" & i) = 14 Then
                Range("K" & i) = 0
                
                    
                        'And when you have done it you want to go down to the next row
                        Selection.Offset(1, 0).Select
                        
                ElseIf .Range("I" & i).Value Like "SUS*" Then
                If Not Range("K" & i) = 0 Or Not Range("K" & i) = 1 Or Not Range("K" & i) = 2 Or Not Range("K" & i) = 3 Or Not Range("K7") = 4 Or Not Range("K" & i) = 5 Or Not Range("K" & i) = 6 Or Not Range("K" & i) = 7 Or Not Range("K" & i) = 8 Or Not Range("K" & i) = 9 Or Not Range("K" & i) = 10 Or Not Range("K" & i) = 11 Or Not Range("K" & i) = 12 Or Not Range("K" & i) = 13 Or Not Range("K" & i) = 14 Then
                Range("K" & i) = 0
                    
                        'And when you have done it you want to go down to the next row
                        Selection.Offset(1, 0).Select
                        
                ElseIf .Range("I" & i).Value Like "SPD*" Then
                If Not Range("K" & i) = 0 Or Not Range("K" & i) = 8 Or Not Range("K" & i) = 9 Or Not Range("K" & i) = 10 Or Not Range("K" & i) = 11 Or Not Range("K" & i) = 12 Then
                Range("K" & i) = 0
    
                    
                        'And when you have done it you want to go down to the next row
                        Selection.Offset(1, 0).Select
                        
                ElseIf .Range("I" & i).Value Like "TAL*" Then
                If Not Range("K" & i) = 0 Or Not Range("K" & i) = 5 Or Not Range("K" & i) = 6 Or Not Range("K" & i) = 7 Or Not Range("K" & i) = 8 Or Not Range("K" & i) = 9 Then
                Range("K" & i) = 0
                
                    
                        'And when you have done it you want to go down to the next row
                        Selection.Offset(1, 0).Select
                        
                ElseIf .Range("I" & i).Value Like "TRA*" Then
                If Not Range("K" & i) = 0 Or Not Range("K" & i) = 6 Or Not Range("K" & i) = 7 Or Not Range("K" & i) = 8 Or Not Range("K" & i) = 9 Or Not Range("K" & i) = 10 Or Not Range("K" & i) = 11 Or Not Range("K" & i) = 12 Or Not Range("K" & i) = 13 Or Not Range("K" & i) = 14 Then
                Range("K" & i) = 0
                    
                        'And when you have done it you want to go down to the next row
                        Selection.Offset(1, 0).Select
                       
        'If Job_Family_Description Is empty then the file is done so we can come out of this IF THEN ELSE Condition
                ElseIf .Range("I" & i).Value = "" Then
                
            End If
            End If
        Next i 'Next without for
    End With

+ 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