Consulting

Results 1 to 8 of 8

Thread: Code Not called on button click

  1. #1
    VBAX Regular
    Joined
    Nov 2018
    Posts
    75
    Location

    Code Not called on button click

    Hi,

    So the following code works on it's own
    Sub PullUniques()
    With Sheets("Line Items")
        Dim rngCell As Range
        For Each rngCell In Range("A2:A1000")
            If WorksheetFunction.CountIf(Range("B2:B1000"), rngCell) = 0 Then
                Range("C" & Rows.Count).End(xlUp).Offset(1) = rngCell
            End If
        Next
        For Each rngCell In Range("B2:B1000")
            If WorksheetFunction.CountIf(Range("A2:A1000"), rngCell) = 0 Then
                Range("D" & Rows.Count).End(xlUp).Offset(1) = rngCell
            End If
        Next
    End With
    End Sub
    but does not work in this button call:
    Sub InsertIsolate()
        Call FileImport
        Call AuditLine
        Call AsBuiltLine
        Call PullUniques
    End Sub

    and I cannot figure out why..any thoughts?

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    U can trial this...
    Sub PullUniques()
    With Sheets("Line Items")
        Dim rngCell As Range
        For Each rngCell In .Range("A2:A1000")
            If WorksheetFunction.CountIf(.Range("B2:B1000"), rngCell) = 0 Then
                .Range("C" & .Rows.Count).End(xlUp).Offset(1) = rngCell
            End If
        Next
        For Each rngCell In .Range("B2:B1000")
            If WorksheetFunction.CountIf(.Range("A2:A1000"), rngCell) = 0 Then
                .Range("D" & .Rows.Count).End(xlUp).Offset(1) = rngCell
            End If
        Next
    End With
    End Sub
    HTH. Dave

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Perhaps because your With…End With is never used:
    Sub PullUniques()
    With Sheets("Line Items")
        Dim rngCell As Range
        For Each rngCell In .Range("A2:A1000")
            If WorksheetFunction.CountIf(.Range("B2:B1000"), rngCell) = 0 Then
                .Range("C" & Rows.Count).End(xlUp).Offset(1) = rngCell
            End If
        Next
        For Each rngCell In .Range("B2:B1000")
            If WorksheetFunction.CountIf(.Range("A2:A1000"), rngCell) = 0 Then
                .Range("D" & Rows.Count).End(xlUp).Offset(1) = rngCell
            End If
        Next
    End With
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Regular
    Joined
    Nov 2018
    Posts
    75
    Location
    Quote Originally Posted by p45cal View Post
    Perhaps because your With…End With is never used:
    Sub PullUniques()
    With Sheets("Line Items")
        Dim rngCell As Range
        For Each rngCell In .Range("A2:A1000")
            If WorksheetFunction.CountIf(.Range("B2:B1000"), rngCell) = 0 Then
                .Range("C" & Rows.Count).End(xlUp).Offset(1) = rngCell
            End If
        Next
        For Each rngCell In .Range("B2:B1000")
            If WorksheetFunction.CountIf(.Range("A2:A1000"), rngCell) = 0 Then
                .Range("D" & Rows.Count).End(xlUp).Offset(1) = rngCell
            End If
        Next
    End With
    End Sub
    Wait, what do you mean the With isn't used? I am confused

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by NWE View Post
    Wait, what do you mean the With isn't used? I am confused
    See https://docs.microsoft.com/en-us/off...6)%26rd%3Dtrue

    You use that With…End With pair of statements, between which you'd expect to see some references beginning with just a dot; there are none.
    I put big red dots in your code to show where they might be missing. Dave did a more thorough job of it.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    VBAX Regular
    Joined
    Nov 2018
    Posts
    75
    Location
    Quote Originally Posted by p45cal View Post
    See https://docs.microsoft.com/en-us/off...6)%26rd%3Dtrue

    You use that With…End With pair of statements, between which you'd expect to see some references beginning with just a dot; there are none.
    I put big red dots in your code to show where they might be missing. Dave did a more thorough job of it.
    Yep..I see it...Thank you Pcal and Dave. I will give that a try and let you guys know what happened.

  7. #7
    VBAX Regular
    Joined
    Nov 2018
    Posts
    75
    Location
    Quote Originally Posted by NWE View Post
    Yep..I see it...Thank you Pcal and Dave. I will give that a try and let you guys know what happened.
    Yea that worked thanks guys.

  8. #8
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    You are welcome. Thanks for posting your outcome. Dave (and P45cal)

Tags for this Thread

Posting Permissions

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