venerdì 19 aprile 2013

m cancella su valore riga

Attribute VB_Name = "m_cancella_su_valore_riga"

'

Option Explicit

'

' vba - excel

' cancella righe che contegono il valore della cella attiva

'

Sub CancellaRigheConValoreCorrente()

'

Dim ColonnaAttiva, corrente As String, quanterighe, contarighe

Dim valore As String, foglio

Set foglio = Sheets(ActiveSheet.Name)

ColonnaAttiva = ActiveCell.Column

valore = Trim(CStr(ActiveCell.Value))

'

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(CStr(foglio.Cells(contarighe, ColonnaAttiva).Value))

If corrente = valore Then

foglio.Rows(contarighe).Delete

End If

Next contarighe

'

Application.ScreenUpdating = True

Application.Cursor = xlDefault

'



End Sub

Nessun commento:

Posta un commento