If/then statement for text string

D

David T

I need a macro that will loop until the last empty cell in column B

This what I need:

If the cells in column "B" contains the word "Total", then copy the cells in
Column "D" to column "E"

This is what I have so far but it is not working. Please help

Sub Copy_subtotal()

Dim i As Integer


i = 4

Do Until IsEmpty(Cells(i, 2))
If Cells(i, 2).Formula = "=RIGHT(RC,5))" = "Total" Then
Cells(i, 4).Copy
Cells(i, 6).Paste

End If

i = i + 1
Loop

End Sub
 
D

Dave Peterson

Maybe...

Option Explicit
Sub Copy_subtotal2()

Dim i As Long
i = 4

Do Until IsEmpty(Cells(i, 2))
If LCase(Left(Cells(i, 2).Value, 5)) = LCase("total") Then
Cells(i, 4).Copy _
Destination:=Cells(i, 6)
End If
i = i + 1
Loop

End Sub
 
D

David T

Dave-

You are the man!!! It works perfect. The only thing i changed in the
formula was from "Left" to "Right" so that it takes the last five letters of
that cell.

Thanks!!!!!!!1
 
D

Dave Peterson

Right, left. It all depends on which side of the monitor you're on! <vbg>.

Glad you got it working.
 
Top