Excel Macro - Search Row for word, move cell value up 1 row

larinda4

Board Regular
Joined
Nov 15, 2021
Messages
73
Office Version
  1. 365
Platform
  1. Windows
Thank you for any help.

I have a rather large data dump I receive and I have to search column E for the word "to". If it comes up, I need the value to the right of the cell (column F) to be moved up 1 row (copy and paste or cut and paste, either one) and then continue searching column E for any other "to"'s.

It sounds very simple but I'm having a hard time finding a code for this.

Here's my code:
VBA Code:
Sub Format_DFG()

Dim cell As Range

Application.ScreenUpdating = False

For Each cell In Range("E1:E" & Cells(Rows.Count, "E").End(xlUp).Row)
If InStr(cell.Text, "to") > 0 Then
cell.Offset(1, 0) = cell.Text
cell.ClearContents
End If
Next cell

Application.ScreenUpdating = True

End Sub

I appreciate the help.
 
Last edited by a moderator:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Welcome to the Board!

Does this do what you want?
VBA Code:
Sub Format_DFG()

Dim cell As Range

Application.ScreenUpdating = False

For Each cell In Range("E1:E" & Cells(Rows.Count, "E").End(xlUp).Row)
    If InStr(cell.Text, "to") > 0 Then
        cell.Offset(-1, 1) = cell.Offset(0, 1).Text
        cell.Offset(0, 1).ClearContents
    End If
Next cell

Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
Welcome to the Board!

Does this do what you want?
VBA Code:
Sub Format_DFG()

Dim cell As Range

Application.ScreenUpdating = False

For Each cell In Range("E1:E" & Cells(Rows.Count, "E").End(xlUp).Row)
    If InStr(cell.Text, "to") > 0 Then
        cell.Offset(-1, 1) = cell.Offset(0, 1).Text
        cell.Offset(0, 1).ClearContents
    End If
Next cell

Application.ScreenUpdating = True

End Sub

THANK YOU SO MUCH! It works!!

If I wanted to cut and paste the value, how would I alter the code?
 
Upvote 0
THANK YOU SO MUCH! It works!!

If I wanted to cut and paste the value, how would I alter the code?
You could use:
VBA Code:
Sub Format_DFG()

Dim cell As Range

Application.ScreenUpdating = False

For Each cell In Range("E1:E" & Cells(Rows.Count, "E").End(xlUp).Row)
    If InStr(cell.Text, "to") > 0 Then
        cell.Offset(0, 1).Cut cell.Offset(-1, 1)
    End If
Next cell

Application.ScreenUpdating = True

End Sub
 
Upvote 0
You could use:
VBA Code:
Sub Format_DFG()

Dim cell As Range

Application.ScreenUpdating = False

For Each cell In Range("E1:E" & Cells(Rows.Count, "E").End(xlUp).Row)
    If InStr(cell.Text, "to") > 0 Then
        cell.Offset(0, 1).Cut cell.Offset(-1, 1)
    End If
Next cell

Application.ScreenUpdating = True

End Sub

The time I'll save scrolling through this data dump is crazy. Thank you so much, Joe! I really truly appreciate it. :)
 
Upvote 0
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

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