If cell equals text then cut and insert

Melrose0507

New Member
Joined
Jul 19, 2011
Messages
22
Hello,

I am having trouble with one part of my macro. The marco is searching column I for the word "TXT". When it finds it, I want it to cut it from I and insert in column L. I need the original cell in column I deleted so every cell to the right will shift left. This is what I have.

Dim LR As Long, i As Long
LR = Range("H" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
With Range("H" & i)
If Cells(i, "H").Value = "TXT" Then .Cut Destination:=shift.Cells(1, i + 4)
End With
Next i

I know the part in red is incorrect but not sure how to code it. I appreciate the assistance.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Use the OFFSET function to move your cell over.



If Cells(i, "H").Value = "TXT" Then
Selection.Cut
ActiveCell.offset(0,5)
ActiveSheet.Paste
ActiveCell.offset(0,-5)

End With
 
Upvote 0
Thanks so much.

VBA does not seem to like the offsets. I have this entered.

Dim LR As Long, i As Long
LR = Range("H" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
With Range("H" & i)
If Cells(i, "H").Value = "TXT" Then
Selection.Cut
ActiveCell.offset(0,5)
ActiveSheet.Paste
ActiveCell.offset(0,-5)
End With
Next i

I get a Compile erorr: Expected: =
It highlighted both the offset lines. Any thoughts?

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top