Hey Leith,
to Q 2:
My emphasis was more on the fact if it's possible to get a value back in case the code is NOT in the criteria list in colorcodes and this value should be the original filename.
to Q 3:
forget about it...![]()
Hey Leith,
to Q 2:
My emphasis was more on the fact if it's possible to get a value back in case the code is NOT in the criteria list in colorcodes and this value should be the original filename.
to Q 3:
forget about it...![]()
Hello Raph,
Are you asking if it is possible to create 2 columns: 1 files that have a matching color code and 1 for those that don't? It is possible to separate the two types.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hello Raph,
I modified the macro to replace only cells that have matching color codes in column "A". If the there is no color code then file name is unchanged.
![]()
Sub ChangeFileNames() 'Revised to change only file names that have a valid color code in column "A" Dim Cell As Range Dim ColorCode As String Dim DSO As Object Dim R As Long Dim RegExp As Object Dim Rng As Range Dim RngEnd As Range Dim Wks As Worksheet Set DSO = CreateObject("Scripting.Dictionary") DSO.CompareMode = vbTextCompare Set RegExp = CreateObject("VBScript.RegExp") RegExp.IgnoreCase = True RegExp.Pattern = "(.+)(\_)(\w{3})(\..+)" Set Wks = Worksheets("ColorCodes") Set Rng = Wks.Range("A1") Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp) Set Rng = Wks.Range(Rng, RngEnd) For Each Cell In Rng Key = Trim(Cell.Text) If Key <> "" Then If Not DSO.Exists(Key) Then DSO.Add Key, Cell.Offset(0, 1).Text End If Next Cell Set Wks = Worksheets("Filenames") Set Rng = Wks.Range("A1") Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp) Set Rng = Wks.Range(Rng, RngEnd) For Each Cell In Rng If RegExp.Test(Cell) = True Then ColorCode = DSO(RegExp.Replace(Cell, "$3")) If ColorCode <> "" Then Cell = RegExp.Replace(Cell, "$1~" & ColorCode & "$4") End If End If Next Cell End Sub
Hey Leith,
my workday was over yesterday so I couldn't aswer you directly.
Thanks for the 1a makro. I have really no idea about the code for the makro, but it's very interesting for me. Do you have a good source for information to get started in that field?
I will compare the two codes to see the differences as soon as I have some time. Quite busy at the moment.
You helped me a lot thank you very much!!!
Raph
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks