+ Reply to Thread
Results 1 to 7 of 7

VBA to put amounts in columns based on Code in column C.

  1. #1
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253

    VBA to put amounts in columns based on Code in column C.

    Need sheet VBA that when a code is put in column C, the amount beside it in column B is put in a column D thru U of the same row based on the code on row 4 of each column.

    In other words, when the code is put in column C, VBA puts the amount in the same row, column B in the same column whose code is in row 4, for example:

    _|__B__|__C_|__D_|__E__|__F__|__G__|__H__|__I__|__J__|__K__|, etc
    4|_Amt_|Code|611_|_648_|_694_|_851_|_862_|_884_|_885_|_886_|, etc
    5|22.01 862_________________________22.01
    6|23.32 851___________________23.32
    7|-4.88 611_-4.88
    8|66.38 885_____________________________________66.38
    9|-4.50 694______________-4.50
    etc

    Thank you for all your help. mikeburg
    Last edited by mikeburg; 02-24-2008 at 08:20 PM. Reason: Put wrong column.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    If you put this in the code module for the sheet in question, it should do what you want. Changing a cell in either column B or C will cause the value in B to be put in the column that matches the column C entry. It does nothing if the entry in C has no match in D4:U4.

    If you want to auto-adjust when the headers (D4:U4) are changed, remove the marked Exit Sub line midway through the code.

    Please Login or Register  to view this content.
    Last edited by mikerickson; 02-24-2008 at 09:26 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  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
    Hello mikeburg,

    Here is another version that automatically finds the last code column, and updates the appropriate cell. This would be placed in the Worksheet_Change event code procedure for the worksheet that has the table.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  4. #4
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253
    Thanks a million. How would you modify it to give a message box when the code could not be found (when entered incorrectly) & remain in the cell where the code was incorrectly entered?

    mikeburg

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253
    With the modification, I get message "Invalid Code" when enter the amount in column B. Sorry, I can't figure out how to fix it where it checks for invalid code in column C.

    Can you help? mikeburg

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    This code will show the message box when the columnC entry is not in D4:U4. The code will run when an entry in either column B or C is changed. Changing column B with a bad entry in column C will trigger the message box.

    This has been modified to not alert when columnC is empty.

    Please Login or Register  to view this content.

+ 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