Comment puis-je mettre à jour ce code VBA afin qu'il puisse s'agir d'une boucle qui vérifie toutes mes colonnes, allant de G4 à G1000 et affiche un msgbox pour chacune et non seulement pour G4?
Private Sub Workbook_Open() Dim c1 As Range Set c1 = ThisWorkbook.Sheets("Sheet1").Range("G4") If IsDate(c1) Then If Now >= c1 + 60 Then MsgBox "The Date in Sheet 1 Cell B4 has been reached or passed." End If End If End Sub
L'utilisation de r.offset (0, -5) se référera à la colonne B
Private Sub Workbook_Open() Dim c1 As Range, r As Range Set c1 = ThisWorkbook.Sheets("Sheet1").Range("G4:G100") For Each r In c1 If IsDate(r.Value) Then If Now >= r.Value + 60 Then MsgBox "warning cell " & r.Address(0, 0) & " is expired: Value: " & r.offset(0,-5) 'r.offset(0,-5) will return the content on col End If End If Next r End Sub
J'espère que cela t'aides.
Peut-être:
Private Sub Workbook_Open() Dim c1 As Range, r As Range Set c1 = ThisWorkbook.Sheets("Sheet1").Range("G4:G100") For Each r In c1 If IsDate(r.Value) Then If Now >= r.Value + 60 Then MsgBox "warning cell " & r.Address(0, 0) & " is expired" End If End If Next r End Sub
Je crois que vous pourriez utiliser ceci: https://msdn.microsoft.com/en-us/library/office/aa221353%28v=office.11%29.aspx
For Each c1 In Worksheets("Sheet1").Range("G4:G1000").Cells ' copy paste your code here Next