mercoledì 18 dicembre 2019

vba - excel - cancella righe del foglio con il valore della cella corrente



'
Option Explicit
'
' vba - excel - cancella righe del foglio con il valore della cella corrente
'
Sub cancellarigheconvalorecorrente()
'
Dim colonnaattiva, corrente As String, quanterighe, contarighe
Dim valorecellaattiva As String, foglio
Set foglio = Sheets(ActiveSheet.Name)
colonnaattiva = ActiveCell.Column
valorecellaattiva = Trim(ActiveCell.Value) ' valore cella attiva
'
Application.Cursor = xlWait
Application.ScreenUpdating = False
'
quanterighe = Range(foglio.UsedRange.Cells(foglio.UsedRange.Rows.Count, 1).Address).Row
'
For contarighe = quanterighe To 1 Step -1                               ' conteggio righe usate
    corrente = Trim(foglio.Cells(contarighe, colonnaattiva).Value)
    If corrente = valorecellaattiva Then
       foglio.Rows(contarighe).Delete
    End If
Next contarighe
'
Application.ScreenUpdating = True
Application.Cursor = xlDefault
'
'
End Sub

Nessun commento:

Posta un commento