Hi,
Can anyone help a complete beginner? My loop below should search a named range for the last 5 charicters in each cell and if they match the last 5 charicters in each cell of the target range, copy the offset value 1 cell to the right from source to target. If they do not match then the source should be inserted at point x in the target range.
I keep getting a block if without end if error at the first if, can anyone advise?
Thanks,
Roy
This is my code:
Sub TestAndCopy()
Dim sourceRange As Range
Dim targetRange As Range
Dim x As Integer
Dim c As Integer
Dim numofRows As Integer
Set sourceRange = [Control_Print_Data_Status_List] 'source workbook
Set targetRange = [Target_Control_Print_Data_Status_List] 'created workbook
numofRows = sourceRange.Rows.Count
x = 51
For c = 1 To numofRows
If sourceRange(c).Right(Value, 5) = targetRange(x).Right(Value, 5) Then Do
sourceRange(c).Offset(0, 1).Value = targetRange(x).Offset(0, 1).Value
x = x + 1
Else
sourceRange(c).Value = targetRange(x).Value
sourceRange(c).Offset(0, 1).Value = targetRange(x).Offset(0, 1).Value
End If
Next c
End Sub
Can anyone help a complete beginner? My loop below should search a named range for the last 5 charicters in each cell and if they match the last 5 charicters in each cell of the target range, copy the offset value 1 cell to the right from source to target. If they do not match then the source should be inserted at point x in the target range.
I keep getting a block if without end if error at the first if, can anyone advise?
Thanks,
Roy
This is my code:
Sub TestAndCopy()
Dim sourceRange As Range
Dim targetRange As Range
Dim x As Integer
Dim c As Integer
Dim numofRows As Integer
Set sourceRange = [Control_Print_Data_Status_List] 'source workbook
Set targetRange = [Target_Control_Print_Data_Status_List] 'created workbook
numofRows = sourceRange.Rows.Count
x = 51
For c = 1 To numofRows
If sourceRange(c).Right(Value, 5) = targetRange(x).Right(Value, 5) Then Do
sourceRange(c).Offset(0, 1).Value = targetRange(x).Offset(0, 1).Value
x = x + 1
Else
sourceRange(c).Value = targetRange(x).Value
sourceRange(c).Offset(0, 1).Value = targetRange(x).Offset(0, 1).Value
End If
Next c
End Sub