+ Reply to Thread
Results 1 to 11 of 11

Substitute parts of Entries by criteria list

Hybrid View

  1. #1
    Registered User
    Join Date
    07-07-2010
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Substitute parts of Entries by criteria list

    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...

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Substitute parts of Entries by criteria list

    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 Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Substitute parts of Entries by criteria list

    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
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    07-07-2010
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Substitute parts of Entries by criteria list

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1