Dim lngRow As Long
Dim lngLastRow As Long
lngLastRow = Range("Y65356").End(xlUp).Row
For lngRow = 2 To lngLastRow
If Range("Y" & lngRow).Value <> "" Then Range("Z" & lngRow).Activate
Windows("rrvtest2.xls").Activate
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND ($AD$&lngRow =""Yes"", $AE$&lngRow=""no"")"
I have changed all the &lngRow originally it was "2"
Selection.FormatConditions(1).Interior.ColorIndex = 6
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND($AD$&lngRow=""Yes"", $AE$&lngRow=""no"")"
Selection.FormatConditions(1).Interior.ColorIndex = 6
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$AE$&lngRow=""Yes"""
Selection.FormatConditions(2).Interior.ColorIndex = 4
Windows("rrvtest2.xls").Activate
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND (Cells($AD$,lngRow)=""Yes"", Cells($AE$,lngRow)=""no"")"
Selection.FormatConditions(1).Interior.ColorIndex = 6
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$AE$&lngRow=""Yes"""
Selection.FormatConditions(2).Interior.ColorIndex = 4
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.Offset(0, 1).Range("A1").Select
Windows("rrvtest2.xls").Activate
ActiveCell.Offset(0, -1).Range("A1").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1

1"), Type:= _
xlFillDefault
ActiveCell.Range("A1

1").Select
ActiveCell.Select
ActiveCell.Offset(0, -1).Range("A1").Select
Windows("rrvtest2.xls").Activate
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Civil"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ActiveCell.Offset(0, 1).Range("A1").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Attachments"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ActiveCell.Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:B1"), Type:= _
xlFillDefault
ActiveCell.Range("A1:B1").Select
ActiveCell.Offset(0, 3).Range("A1").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND($AD$&lngRow=""Yes"", $AE$&lngRow=""no"")"
Selection.FormatConditions(1).Interior.ColorIndex = 6
ActiveCell.Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND($AD$&lngRow=""Yes"", $AE$&lngRow=""no"")"
Selection.FormatConditions(1).Interior.ColorIndex = 6
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$AE$&lngRow=""Yes"""
Selection.FormatConditions(2).Interior.ColorIndex = 4
ActiveCell.Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Yes"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ActiveCell.Offset(0, 1).Range("A1").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Yes"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$AQ$&lngRow=Yes"
Selection.FormatConditions(1).Interior.ColorIndex = 4
ActiveCell.Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:L1"), Type:= _
xlFillDefault
ActiveCell.Range("A1:L1").Select
ActiveCell.Select
ActiveCell.FormulaR1C1 = ""
ActiveCell.Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=IE"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ActiveCell.Offset(0, 1).Range("A1").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Labour"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ActiveCell.Select
Selection.Copy
ActiveCell.Offset(0, 2).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 2).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 2).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 2).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 2).Range("A1").Select
Application.CutCopyMode = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Yes"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
'Range("Z" & lngRow).Value = Range("Z" & lngRow).Value + 1
Next lngRow
End Sub
Im trying to run a macro on differnt lines hence why i need the formatting to be a variable.
Any ideas?