Move data to other fields with condition

Excer

New Member
Joined
Dec 14, 2023
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I would like to move data (column G, H, I, J, L and M) to one row above (With condition only if there is a word "EA" on column B or a word "X" on column D)
Is there any formula or macro for doing it?
Here is an example:
1702622267044.png


Thank you
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I haven't tested it. Try:
VBA Code:
Sub test()
  Dim lRow As Long, i As Long
  lRow = Cells(Rows.Count, "B").End(xlUp).Row
  For i = 1 To lRow
    If Cells(i, "B").Value2 = "EA" And Cells(i, "D").Value2 = "X" Then
      Cells(i, "G").Offset(-1).Resize(, 4).Value2 = Cells(i, "G").Resize(, 4).Value2
      Cells(i, "L").Offset(-1).Resize(, 2).Value2 = Cells(i, "L").Resize(, 2).Value2
      Cells(i, "G").Resize(, 4).Value2 = ""
      Cells(i, "L").Resize(, 2).Value2 = ""
    End If
  Next
End Sub
 
Upvote 0
I haven't tested it. Try:
VBA Code:
Sub test()
  Dim lRow As Long, i As Long
  lRow = Cells(Rows.Count, "B").End(xlUp).Row
  For i = 1 To lRow
    If Cells(i, "B").Value2 = "EA" And Cells(i, "D").Value2 = "X" Then
      Cells(i, "G").Offset(-1).Resize(, 4).Value2 = Cells(i, "G").Resize(, 4).Value2
      Cells(i, "L").Offset(-1).Resize(, 2).Value2 = Cells(i, "L").Resize(, 2).Value2
      Cells(i, "G").Resize(, 4).Value2 = ""
      Cells(i, "L").Resize(, 2).Value2 = ""
    End If
  Next
End Sub
Thanks for your help. I don't have the chance to try it. Every time I ran the report, the format kept changing. Thanks anyway.
 
Upvote 0

Forum statistics

Threads
1,215,964
Messages
6,127,966
Members
449,414
Latest member
sameri

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