I'm not sure how to ask this... Lookup multiple cell values and then change the text of the adjacent cell depending on what the value says

jmcginley3

New Member
Joined
Mar 28, 2018
Messages
14
On a weekly basis I receive 20-30 files and they all have to be renamed to a specific format so our automated system will pick them up and send them where they need to go.

I made a spreadsheet with a very simple macro that pulls in the files from the specified folder and places all the file names in column A (file names start in A2). Then in column B I can type in how each corresponding file from column A should be renamed. Then I have a macro that just renames A2 to whatever I have in B2, A3 to B3, etc etc.

To take it a step further, about 80% of the files I receive are going to be named the same when I get them so I figured I could use a macro or formula to look for these files and automatically rename them. Here's some examples of what I mean:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Old File Name[/TD]
[TD]New File Name[/TD]
[/TR]
[TR]
[TD]PLAN_PAY_BY_PRODUCT_351NE4737Y[/TD]
[TD]PlanPayByProductCode_MMDDYYYY[/TD]
[/TR]
[TR]
[TD]DAILY_CHECKEFT_REISSUES_3YNE8FH34[/TD]
[TD]Daily_check_eft_reissues_MMDDYYY[/TD]
[/TR]
[TR]
[TD]DETAIL_GROUP_ACTIVITY_1_58J859H[/TD]
[TD]GroupActivityDetail_MMDDYYY[/TD]
[/TR]
</tbody>[/TABLE]


In the Old File Name column there are generally around 30 different files and they are never in the same order.

If I can look in all of column A for PLAN_PAY_BY_PRODUCT* (because that last code after the final underscore always changes on every file) and then have it automatically enter PlanPayByProductCode_MMDDYYYY (with the current month, day, year) in the cell directly adjacent in column B then it would cut down even more time renaming these files every day. I'd need to do that for every file name that can automatically be changed.

Any idea on how to best handle this? Thanks in advance!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Maybe something like this

Code:
Sub renamefiles()
Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lr
    If Left(Cells(x, 1), 20) = "PLAN_PAY_BY_PRODUCT_" Then Cells(x, 2) = "PlanPayByProductCode_" & Format(Date, "MMDDYYYY")
    If Left(Cells(x, 1), 24) = "DAILY_CHECKEFT_REISSUES_" Then Cells(x, 2) = "Daily_check_eft_reissues_" & Format(Date, "MMDDYYYY")
    If Left(Cells(x, 1), 22) = "DETAIL_GROUP_ACTIVITY_" Then Cells(x, 2) = "GroupActivityDetail_" & Format(Date, "MMDDYYYY")
    'add more if statments for other file names
Next x

End Sub
 
Upvote 0
That's perfect! It works great. Thanks so much for your help! Now I'll get started plugging in the file names. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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