I have this code that loops though Cells on a whorksheet to add data validation. I have 4 loops one for each Column, the Rows auto-populate in the excel table.
I'm sure there's a better way to write the code with 2 for loops and adding A B C D to each of them, any help whould be great thanks.
For I = 8 To Mid(last_cell, 4, 3)
With Current_Worksheet.Range("C" & I).Cells.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=A104:A152"
.IgnoreBlank = True
.InCellDropdown = True
.ErrorMessage = "The time entered must be in multples of 15 minutes" & vbCrLf & " Between 6:30AM and 6:30PM"
.ShowInput = True
.ShowError = True
End With
Next I
For I = 8 To Mid(last_cell, 4, 3)
With Current_Worksheet.Range("D" & I).Cells.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=A104:A152"
.IgnoreBlank = True
.InCellDropdown = True
.ErrorMessage = "The time entered must be in multples of 15 minutes" & vbCrLf & " Between 6:30AM and 6:30PM"
.ShowInput = True
.ShowError = True
End With
Next I
For I = 8 To Mid(last_cell, 4, 3)
With Current_Worksheet.Range("E" & I).Cells.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=A104:A152"
.IgnoreBlank = True
.InCellDropdown = True
.ErrorMessage = "The time entered must be in multples of 15 minutes" & vbCrLf & " Between 6:30AM and 6:30PM"
.ShowInput = True
.ShowError = True
End With
Next I
For I = 8 To Mid(last_cell, 4, 3)
With Current_Worksheet.Range("F" & I).Cells.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=A104:A152"
.IgnoreBlank = True
.InCellDropdown = True
.ErrorMessage = "The time entered must be in multples of 15 minutes" & vbCrLf & " Between 6:30AM and 6:30PM"
.ShowInput = True
.ShowError = True
End With
Next I