Jump to content
Fórum Script Brasil
  • 0

Macro valores não repetidos


VanOliveira

Question

Olá! Estou a tentar programar uma macro em VBA que corra a linha A, encontre o campo "Pagador" e devolva o número de valores diferentes presentes na respetiva coluna. No entanto, quando corro a macro o excel bloqueia e penso que entra em loop infinito e não consigo perceber porquê. Alguém me consegue ajudar? O código que estou a usar é:

 

Private Sub CommandButton2_Click()

Dim scol As New Collection
Dim MyAr As Variant
Dim x As Long
Dim z As Integer

Sheets("Aux").Activate
Sheets("Aux").Range("A1").Select

Do While ActiveCell.Value <> ""

If ActiveCell.Value = "Pagador" Then
    With Sheets("AUX")
    C = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
    A = ActiveCell.Offset(1, 0)
    B = ActiveCell.Offset(C, 0)
   

MyAr = .Range("A:B").Value
    
    For i = 1 To UBound(MyAr)
        On Error Resume Next
        scol.Add MyAr(i, 1), Chr(34) & _
        MyAr(i, 1) & Chr(34)
        On Error GoTo 0
        Next i
    End With
    x = scol.Count
Else
ActiveCell.Offset(0, 1).Select

End If
Loop

Sheets("Customer").Range("C32") = x
End Sub
 

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      652k
×
×
  • Create New...