mercoledì 13 marzo 2013

cancella righe scadute per data

Attribute VB_Name = "cancella_righe_scadute_per_data"

'

Option Explicit

'

' vba - Cancella Righe Scadute Per Data

'

Sub CancellaRigheScadutePerData()

'

Dim txtinfo, colonnaselezionata, corrente, lungo, quanterighe, contarighe

Dim oggi As Date, foglio

Set foglio = Sheets(ActiveSheet.Name)

txtinfo = "cancella righe scadute" & vbCrLf & "data inferiore ad oggi"

'

colonnaselezionata = InputBox(txtinfo, "scegli colonna")

'

Application.Cursor = xlWait

Application.ScreenUpdating = False

'

oggi = Date

quanterighe = Range(foglio.UsedRange.Cells(foglio.UsedRange.Rows.Count, 1).Address).Row

' verifica la presenza del dato

lungo = Len(Trim(colonnaselezionata))

If lungo = 0 Then

Exit Sub

End If

'

For contarighe = quanterighe To 1 Step -1

corrente = Trim(foglio.Cells(contarighe, colonnaselezionata).Value)

If IsDate(corrente) = True Then

If corrente < oggi Then

foglio.Rows(contarighe).Delete

End If

End If

'

Next contarighe

'

Application.ScreenUpdating = True

Application.Cursor = xlDefault

'

End Sub

Nessun commento:

Posta un commento