+ Reply to Thread
Results 1 to 4 of 4

Create Sub routine that translates values

Hybrid View

  1. #1
    Registered User
    Join Date
    01-26-2015
    Location
    Massachusetts
    MS-Off Ver
    2016
    Posts
    73

    Create Sub routine that translates values

    We’re using a complicated macro to clean and format data into several sheets. I’d like to add the following functionality to the existing macro using vba. I’d like to accomplish this functionality solely in the VBA code and not have to use another sheet or copy additional columns and rows with the values. I would like to accomplish this using and IF THEN ELSE statement in the vba code.

    IF B2 = “Giving” and D2 = “general fund” then D2 changes to 0501
    ELSE IF
    B2 = “Giving” and D2 = “global fund” then D2 becomes 0502
    ELSE IF
    B2=”Giving” and D2 =”” then D2 becomes 0501
    ELSE IF
    B2 =”Athletics” and D2 = “Friends of Athletics” then D2 becomes 0601
    ELSE IF
    B2 =”Athletics” and D2 = “” then D2 becomes “”
    Etc.
    I’ll have about 20 different options I’ll add.

    Thanks for your help.
    Last edited by wwconslt; 04-17-2018 at 10:12 AM.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Create Sub routine that translates values

    Without full list and/or sample workbook, can't give you exact code.

    But I'd imagine, you could first start by creating dictionary/collection/array to store these conditions and use lookup operation in code to change destination value.

    Though, I'd recommend storing lookup table elsewhere, to simplify and speed up process.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    01-26-2015
    Location
    Massachusetts
    MS-Off Ver
    2016
    Posts
    73

    Re: Create Sub routine that translates values

    Thanks CK76. I'm trying to avoid having a user bring in a sheet that has the lookup table/array. Where/how could I store the lookup table?

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Create Sub routine that translates values

    Simple example using dictionary.
    Sub Demo()
    Dim dic As Object
    
    Set dic = CreateObject("Scripting.Dictionary")
    With dic
        .Add "Giving,general fund", "0501"
        .Add "Giving,global fund", "0502"
        .Add "Giving,", "0501"
        .Add "Athletics,Friends of Athletics", "0601"
        'more Key, Item pair
    End With
    
    [D2].Value = dic([B2].Value & "," & [D2].Value)
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Sub routine For Making Directories if not exisisting create
    By COURTTROOPER in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2017, 06:35 AM
  2. HELP! Can't correctly create Find & Replace macro routine for Word doc
    By staggers47 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2012, 09:51 PM
  3. Routine to create navigation buttons
    By allanr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2008, 04:30 AM
  4. Excel crashes when I create code through a routine
    By Caligula in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2007, 03:55 PM
  5. Create a range that translates to a numeric value?
    By swaddock in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 07-06-2007, 10:57 AM
  6. How to create a routine
    By Tara in forum Excel General
    Replies: 1
    Last Post: 08-11-2005, 10:05 PM

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