Sub SelezionaRange() Dim RigI As Long, NriF As Long Dim i As Long, conta As Long conta = 0 For i = 1 To Cells(Rows.Count, 2).End(xlUp).Row If Cells(i, 2).Value = Date Then If conta = 0 Then RigI = i conta = 1 Else NriF = i End If End If Next i Set area = Application.ThisWorkbook.Worksheets("INPUT").Range(Cells(RigI, "A"), Cells(NriF, "J")) Range(Cells(RigI, "A"), Cells(NriF, "J")).Select End Sub
Sub cerca() Dim R1 As Long, R2 As Long, Area As range, Rg As Object, Data As Date Data = #1/2/2018# 'attento cerca il 2/1/2018 Set Area = Sheets("Foglio1").range("B:B") Set Rg = Area.Find(Data, LookIn:=xlValues, LookAt:=xlWhole) If Rg Is Nothing Then 'oppure If Not Rg Is Nothing Then togliendo le due righe sotto MsgBox "nessuna corrispondenza" Else R1 = Rg.Row 'prima riga trovata End If Set Rg = Area.Find(Data + 1, LookIn:=xlValues, LookAt:=xlWhole) If Rg Is Nothing Then MsgBox "nessuna corrispondenza" Else R2 = Rg.Row - 1 'ultima riga trovata End If Set Area = Sheets("Foglio1").range(Cells(R1, 1), Cells(R2, 100)) 'se non funziona 'Set Area = Sheets("Foglio1").range(Sheets("Foglio1").Cells(R1, 1), Sheets("Foglio1").Cells(R2, 100)) Set Rg = Nothing Set Area = Nothing End Sub
For X = R1 To Ur If Cells(X, 2) = Data Then R2 = X Else Exit For End If Next X