If a cell contains certain keyword, then move values from 1 cell to another (same row)

zack8576

Active Member
Joined
Dec 27, 2021
Messages
271
Office Version
  1. 365
Platform
  1. Windows
I need to modify a bunch of excel files, for any row that contains the word "Skimmer", I need to move the value from column B (same row) to in front of Skimmer (always in column K)
like this: (1)Skimmer, (2)Skimmer, (3)Skimmer. (The value in column B does not need to be removed)

see below for example file, code is also below, this is not working for me....
any help is appreciated, dropbox link for the example file is also below

1672869342967.png


VBA Code:
Sub AssignStructureIDToSkimmer()
   With Range("K2:K" & Range("K" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate(Replace(Replace("If(" & .Offset(, 10).Address & "=""Skimmer"","" ""&@,if(@="""","""",@))", "@", .Address), "#", .Offset(, 9).Address))
   End With
End Sub

 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Does your version actually require the IF({1}...) part of the formula? Mine doesn't, and therefore the OP's shouldn't (also using 365), require that extra calculation.
Without that, our codes are identical apart from the order.
thanks Peter, BTW what does the IF({1}....) do anyways?
 
Upvote 0
It is a way to force a calculation to work over an array of cells but is not required for you. Therefore the code in post #3 would be a slightly simpler way for you to go as it eliminates one calculation step.
Not that important either way though. :)
 
Upvote 0
It is a way to force a calculation to work over an array of cells but is not required for you. Therefore the code in post #3 would be a slightly simpler way for you to go as it eliminates one calculation step.
Not that important either way though. :)
Thank you Peter, for all the help !
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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