top of page
Buscar

Como seleccionar filas por tipo de texto y eliminar el resto...

  • Foto del escritor: Carlos Cerrato
    Carlos Cerrato
  • 13 feb 2016
  • 1 Min. de lectura

Necesitamos eliminar todas las filas que no esten en NEGRITA. Para ello te propongo este código:

Set borrar = Range("A5000") ' SELECCIONAR LAS REGIONES en TIPO NEGRITA For Each CELDA In Worksheets("TEMP").Range("C2:C64") If CELDA.Font.Bold <> True Then Set otro = Worksheets("TEMP").Range("A" & CELDA.Row & ":Z" & CELDA.Row) Set borrar = Union(borrar, otro) Debug.Print borrar.Address End If Next Worksheets("TEMP").Range(borrar.Address).EntireRow.Delete

EXPLICACION:

  1. DEFINIMOS UN OBEJTO RANGO, "BORRAR"

  2. REALIZAMOS UN BUCLE FOR EACH PARA CADA CELDA EN ESE RANGO (EN ESTE CASO LAS REGIONES ESTAN EN LA COLUMNA C)

  3. CON EL IF, PREGUNTAMOS SOBRE SI EL TEXTO ES DISTINTO DE NEGRITA

  4. EN CASO AFIRMATIVO CREAMOS UN OBJETO RANGE CON LA DIRECCION DE ESA FILA

  5. MEDIANTE "UNION" CREAMOS AÑADIMOS RANGOS AL RANGO BORRAR (YA EXISTENTE)

  6. AL FINAL BORRARMOS ESE RANGO

Comentarios


Entradas destacadas
Entradas recientes
Archivo
Buscar por tags
Síguenos
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page