Consulting

Results 1 to 3 of 3

Thread: Criteria Problem

  1. #1
    VBAX Contributor
    Joined
    Aug 2007
    Posts
    188
    Location

    Criteria Problem

    Hi

    I cannot get my head around "Criteria" and I have attached
    a very simple example that I need help with -- I want to place
    a CommandButton on an exsisting UserForm and on Click it will
    run a Sub to solve my problem

    Many Thanks

    Sooty 8

  2. #2
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    Here's a sample of code that will make your example do what I think you are looking for:
    [vba]Option Base 1
    Private Sub CommandButton1_Click()
    Dim criteria11(2, 2) As String
    Dim criteria3() As String
    'Tests first criteria.
    i = 1
    For x = 1 To Sheet5.UsedRange.Rows.Count
    If Sheet5.Range("F" & x) = 11 Then
    criteria11(1, i) = Sheet5.Range("B" & x) & " " & Sheet5.Range("A" & x) '<<Little discrepancy between the data _
    'in column B of Sheet5 and Sheet12. _
    'One sheet has "J." and the other "J. ".
    criteria11(2, i) = Sheet5.Range("E" & x)
    i = i + 1
    End If
    If i = 3 Then Exit For
    Next
    'Tests second criteria.
    j = 1
    ReDim criteria3(2, 1)
    For x = 1 To Sheet12.UsedRange.Rows.Count
    If Sheet12.Range("F" & x) = 3 Then
    criteria3(1, j) = Sheet12.Range("B" & x) & Sheet12.Range("A" & x)
    criteria3(2, j) = Sheet12.Range("E" & x)
    j = j + 1
    ReDim Preserve criteria3(2, j)
    End If
    Next
    'Compares criterias and writes results.
    For i = 1 To j
    If criteria3(1, i) = criteria11(1, 1) Then
    Sheet14.Range("B13") = criteria11(1, 1)
    Sheet14.Range("F13") = criteria11(2, 1)
    End If
    If criteria3(1, i) = criteria11(1, 2) Then
    Sheet14.Range("B14") = criteria11(1, 2)
    Sheet14.Range("F14") = criteria11(2, 2)
    End If
    Next
    End Sub
    [/vba]
    Paste it in the declarations of a userform with a CommandButton1, and it should work for you.

  3. #3
    VBAX Contributor
    Joined
    Aug 2007
    Posts
    188
    Location
    Hi Nate

    Thanks for the reply and I apologise for the delay in replying been off colour with a bad head cold - your help was invaluable and worked OK however probably because of not feeling to good I missed loads of stuff off what should have been my original full question -- want to work on it over the weekend and then post again - in this post and perhaps you can help me again.

    Many Thanks - your help is much appreciated.

    Sooty 8

Posting Permissions

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