Sub contar()
'Por.Dante Amor
Application.ScreenUpdating = False
Set h1 = Sheets("GASTOS")
Set h2 = Sheets("Hoja1")
h2.Cells.Clear
h2.Range("A1:B1") = Array("USUARIOS", "CONTEO")
For i = 3 To h1.Range("X" & Rows.Count).End(xlUp).Row
If h1.Cells(i, "X") <> "" Then
Set b = h2.Columns("A").Find(h1.Cells(i, "X"))
If Not b Is Nothing Then
If h2.Cells(b.Row, "C") <> h1.Cells(i, "A") Then
h2.Cells(b.Row, "B") = h2.Cells(b.Row, "B") + 1
h2.Cells(b.Row, "C") = h1.Cells(i, "A")
tot = tot + 1
End If
Else
j = h2.Range("A" & Rows.Count).End(xlUp).Row + 1
h2.Cells(j, "A") = h1.Cells(i, "X")
h2.Cells(j, "B") = 1
h2.Cells(j, "C") = h1.Cells(i, "A")
tot = tot + 1
End If
End If
Next
h2.Cells(j + 2, "B") = tot
h2.Columns("C").Clear
h1.Select
For i = h1.Cells(2, Columns.Count).End(xlToLeft).Column To 1 Step -1
If Application.CountA(h1.Columns(i)) = 0 Then
h1.Columns(i).Delete
End If
Next
'h1.Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
h1.Columns("F:F").SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[1]C"
h1.Columns("F:F").Copy
h1.Range("F1").PasteSpecial Paste:=xlPasteValues
u = h1.Range("A" & Rows.Count).End(xlUp).Row
With h1.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("F3:F" & u), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Range("A2:I" & u)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
u = h1.Range("A" & Rows.Count).End(xlUp).Row
u2 = h1.Range("F" & Rows.Count).End(xlUp).Row
If u2 > u Then h1.Range("A" & u + 1 & ":I" & u2).Clear
h1.Range("A1").Select
Application.ScreenUpdating = True
MsgBox "Conteo terminado", vbInformation
End Sub
Recuerda valorar la respuesta