Hi: I have data in col A and B. I'd like to build a macro that, if it finds the term "trigger" in col A, it copies the data in col B to col C (all in the same row). But, if it doesn't find the term "trigger" in col A, it copies the prior successful data to col C. Here's what I have so far ...
[TABLE="width: 482"]
<tbody>[TR]
[TD]Col A[/TD]
[TD]Col B[/TD]
[TD]Col C[/TD]
[/TR]
[TR]
[TD]Trigger[/TD]
[TD]Blue[/TD]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]Not Trigger[/TD]
[TD]Yellow[/TD]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]Not Trigger[/TD]
[TD]Red[/TD]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]Trigger[/TD]
[TD]Green[/TD]
[TD]Green[/TD]
[/TR]
</tbody>[/TABLE]
Thank you!
Code:
Sub Data_Copy()
Dim i As Long
Dim myValue As String
Dim LastRow As Long
Dim StartRow As Long
StartRow = 1
LastRow = Range("A" & StartRow).End(xlDown).Row
For i = StartRow To LastRow
myValue = Range("A" & i).Value
If myValue = "Trigger" Then
Range("C" & i).Value = Range("B" & i).Value
Else: Range("C" & i).Value = myValue
End If
Next i
End Sub
[TABLE="width: 482"]
<tbody>[TR]
[TD]Col A[/TD]
[TD]Col B[/TD]
[TD]Col C[/TD]
[/TR]
[TR]
[TD]Trigger[/TD]
[TD]Blue[/TD]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]Not Trigger[/TD]
[TD]Yellow[/TD]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]Not Trigger[/TD]
[TD]Red[/TD]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]Trigger[/TD]
[TD]Green[/TD]
[TD]Green[/TD]
[/TR]
</tbody>[/TABLE]
Thank you!