Macro para delegar un rango desde un textbox

Buenas dias
me gustaria que me colaboraran tengo un codigo que me pinata los datos  repetidos, paro quisiera que este codigo no  me pinte los espacios en blanco y que yo le pueda designar el rango en que va actuar desde un texbox
gracias
Sub coloreaDup()
'x Elsamatilde
'controla col A
Range("A2").Select
ultima = Range("A65536").End(xlUp).Row
'recorro hasta la fila última
While ActiveCell.Row <= ultima
'guardo fila para volver del bucle
filax = ActiveCell.Row
'controlo si aún no tiene color
If ActiveCell.Interior.ColorIndex = xlNone Then
    dato = ActiveCell.Value
    Do
    ActiveCell.Offset(1, 0).Select
    If ActiveCell = dato Then
        ActiveCell.Interior.ColorIndex = 4
        'opcional: colorear también el dato original
        Cells(filax, 1).Interior.ColorIndex = 4
    End If
    Loop While ActiveCell.Row <= ultima And ActiveCell.Row <> filax
End If
'paso a la fila sgte y repito el bucle
Cells(filax + 1, 1).Select
Wend
End Sub

1 respuesta

Respuesta
1
Prueba este macro.
Public Sub Start()
    On Error GoTo Finalizar
    Dim RangoColumnas As Range
    Set RangoColumnas = Application.InputBox("Por favor, seleccione el rango de columnas", Type:=8)
    'RangoColumnas.Application.ActiveCell
    If RangoColumnas.Columns.Count = 1 Then
       Dim IniCell As String
       IniCell = Mid(RangoColumnas.Address(0, 0), 1, InStr(1, RangoColumnas.Address(0, 0), ":", vbTextCompare) - 1)
       EndCell = Replace(RangoColumnas.Address(0, 0), IniCell & ":", "")
        Call coloreaDup(RangoColumnas, IniCell, EndCell)
    Else
        MsgBox "Por favor debe seleccionar una sola columna.", vbInformation
    End If
Exit Sub
Finalizar:
MsgBox "Se produjo un error.", vbInformation
End Sub
Private Sub coloreaDup(ByVal Rango As Range, IniCell As String, EndCell)
'x Elsamatilde
'controla col A
Range(EndCell).Offset(1, 0).Select
ultima = ActiveCell.End(xlUp).Row
Range(IniCell).Select
'recorro hasta la fila última
While ActiveCell.Row <= ultima
'guardo fila para volver del bucle
filax = ActiveCell.Row
columnax = ActiveCell.Column
'controlo si aún no tiene color
If ActiveCell.Interior.ColorIndex = xlNone Then
    dato = ActiveCell.Value
    Do
    ActiveCell.Offset(1, 0).Select
    If ActiveCell = dato And ActiveCell.Value <> "" Then
        ActiveCell.Interior.ColorIndex = 4
        'opcional: colorear también el dato original
        Cells(filax, columnax).Interior.ColorIndex = 4
    End If
    Loop While ActiveCell.Row <= ultima And ActiveCell.Row <> filax
End If
'paso a la fila sgte y repito el bucle
Cells(filax + 1, columnax).Select
Wend
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas