Hi everyone,
I've written some lines of code to enter formulas in different cells depending on the value of a column's cells. Everything goes smoothly up until I hit the 'else statement'. What is weird is that the 'else statement' is virtually identical to the 'if statement', just using different cell references. Can anybody help me think through this? I'm at a loss for what the issue is (any other tips would be appreciated too). Here's the code:
Dim LastRow As Long
LastRow = Worksheets("Item Details").Range("D1").CurrentRegion.Rows.Count
' ^Identifies the last row in the worksheet and assigns to variable "LastRow"
Dim Rng As Range
Dim Cell As Range
Set Rng = Range(Cells(2, 24), Cells(LastRow, 24))
' ^Assigns the range of X2 down to the last row in column X to the variable "Rng"
Range("x2").Select
Dim x As Integer
For x = 2 To LastRow
If ActiveCell.Value = "CY-" Then
ActiveCell.Offset(0, 8).Formula = ActiveCell.Offset(0, 17).Value & ActiveCell.Offset(0, -10).Value
ActiveCell.Offset(0, 9).Formula = ActiveCell.Offset(0, 18).Value & ActiveCell.Offset(0, -10).Value
ActiveCell.Offset(0, 10).Formula = ActiveCell.Offset(0, 19).Value & ActiveCell.Offset(0, -10).Value
ActiveCell.Offset(0, 11).Formula = ActiveCell.Offset(0, 17).Value & ActiveCell.Offset(0, -8).Value
ActiveCell.Offset(0, 12).Formula = ActiveCell.Offset(0, 18).Value & ActiveCell.Offset(0, -8).Value
ActiveCell.Offset(0, 13).Formula = ActiveCell.Offset(0, 19).Value & ActiveCell.Offset(0, -8).Value
ActiveCell.Offset(0, 14).Formula = ActiveCell.Offset(0, 17).Value & ActiveCell.Offset(0, -9).Value
ActiveCell.Offset(0, 15).Formula = ActiveCell.Offset(0, 18).Value & ActiveCell.Offset(0, -9).Value
ActiveCell.Offset(0, 16).Formula = ActiveCell.Offset(0, 19).Value & ActiveCell.Offset(0, -9).Value
ActiveCell.Offset(1, 0).Select
Else <--------------------------------------------------------------------------------------------------------------------------------Error given when moving to 'else'
ActiveCell.Offset(0, 5).Formula = ActiveCell.Offset(0, 3).Value & ActiveCell.Offset(-10).Value
ActiveCell.Offset(0, 6).Formula = ActiveCell.Offset(0, 3).Value & ActiveCell.Offset(-8).Value
ActiveCell.Offset(0, 7).Formula = ActiveCell.Offset(0, 3).Value & ActiveCell.Offset(-9).Value
ActiveCell.Offset(1, 0).Select
End If
Next
Thanks!
Bookmarks