+ Reply to Thread
Results 1 to 5 of 5

VBA Code to Update Cell in Column Based on Value from Drop Down List

  1. #1
    Registered User
    Join Date
    12-04-2020
    Location
    Houston, Tx
    MS-Off Ver
    365
    Posts
    14

    VBA Code to Update Cell in Column Based on Value from Drop Down List

    Hello,

    I need a VBA code to look at each cell in a particular column and update the specific cell content to include a formula.

    If the cell in Column A is blank, I need there to be a formula in it that reads {=IFERROR(INDEX(Description_A,MATCH(B3,SKU_A,0)),"")}

    However, I also need to be able to have a drop down list in Column A that reads:

    Lemon
    Cherry
    Grapes

    So that if I select either of those three, I can type in the corresponding SKU number in SKU List B.

    Column B will have a constant formula in it that contains {=IFERROR(INDEX(SKU_B,MATCH(A2,Description_B,0)),"")} which will be overridden if I have the SKU number handy.

    Just a background of my dilemma, I have a long list of SKU's and products, but sometimes the people building the pallets are unable to find the product on that list, so they handwrite the description at the end of the list. I want to be able to key in the SKU's that are present on the sheet they turn in in column B, but if they hand write something, I need to be able to select the hand written description in column A so that the formula in Column B will look up and output the respective SKU... sorry if this is overly complicated.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,474

    Re: VBA Code to Update Cell in Column Based on Value from Drop Down List

    Quick apology, added file before remembering to Set the Col K and L ranges, so you need to replace the formula with those below.

    Attached has two "circular" references in Cols A and B in each row

    In Col A, row 2 and copied down:
    =IFERROR(INDEX(K$2:K$7,MATCH(B2,L$2:L$7,0)),"")

    And in Col B, row 2 and copied down:
    =IFERROR(INDEX(L$2:L$7,MATCH(A2,K$2:K$7,0)),"")

    Entering an SKU in Col B "overwrites" that formula, but the formula in Col A finds the matching Product.

    And if you have only the Description but no SKU, enter it in Col A. That "overwrites" that formula, but the formula in Col B fetches the SKU.

    Obviously you either recreate the Formulae on a clean sheet each day, or have a blank "Master" that you copy and date?

    Unorthodox, but solves it for you

    Ochimus
    Attached Files Attached Files
    Last edited by Ochimus; 12-10-2020 at 08:59 PM.

  3. #3
    Registered User
    Join Date
    12-04-2020
    Location
    Houston, Tx
    MS-Off Ver
    365
    Posts
    14

    Re: VBA Code to Update Cell in Column Based on Value from Drop Down List

    Thanks for the response Ochimus. Unfortunately, I need to be able to select from a dropdown list in column A. I found a post on another site that sort of did it, but it only applied to a dropdown list in one cell, where I need the drop down for the entire column.. I also don't need a "constant data range" like the VBA below indicates. Nevertheless, it would work with some minor tweaking for an entire column, I just don't really know how to do that.

    [B][B]Select cell A1 and add your validation list with this source value:

    None,Average,Count,Count Numbers,Max,Min,Sum,StdDev,Var,Other Functions...

    Add this code to the worksheet code module:

    Private Sub Worksheet_Change(ByVal Target As Range)

    Const RangeReference = "$B$1:$B$10"

    Dim Value As Variant

    If Not Intersect(Target, [A1]) Is Nothing Then
    Application.EnableEvents = False
    Select Case [A1].Value
    Case "None"
    Value = vbNullString
    Case "Average"
    Value = "=AVERAGE(^RangeReference)"
    Case "Count"
    Value = "=COUNT(^RangeReference)"
    Case "Count Numbers"
    Value = "=SUMPRODUCT(ISNUMBER(^RangeReference)*1)"
    Case "Max"
    Value = "=MAX(^RangeReference)"
    Case "Min"
    Value = "=MIN(^RangeReference)"
    Case "Sum"
    Value = "=AVERAGE(^RangeReference)"
    Case "StdDev"
    Value = "=STDEV.P(^RangeReference)"
    Case "Var"
    Value = "=VAR(^RangeReference)"
    Case "Other Functions...":
    Application.Dialogs(xlDialogFunctionWizard).Show
    End Select
    If VarType(Value) = vbString Then
    [A1].Formula = Replace(Value, "^RangeReference", RangeReference)
    ElseIf Not IsEmpty(Value) Then
    [A1].Value = Value
    End If
    Application.EnableEvents = True
    End If

    End Sub

  4. #4
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,474

    Re: VBA Code to Update Cell in Column Based on Value from Drop Down List

    j,

    Quick point. Need to amend your post by adding the word Code in square brackets before the word Private Sub and at the end.

    Ochimus
    Last edited by Ochimus; 12-15-2020 at 08:47 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,474

    Re: VBA Code to Update Cell in Column Based on Value from Drop Down List

    J,

    A DropList relates to one cell only. If you want the same list available for ten cells, you have to have ten DropLists.
    What you seem to be asking for is a DropList that contains both Product names and an "Index/Match" formula that links automatically to whichever row you are working on, so it will produce the relevant SKU.
    As far as I am aware, that can't be done, as it is not one of the Functions programmed into DropLists.
    Nor can you do it with a Combobox, because that also "Links" to one cell only, so for a hundred rows you need one hundred Comboboxes.

    If you definitely need the DropLists in Col A with the three Products, my approach would be to set the DropList to allow other text, then create a "worksheet change" Macro triggered by you entering any other name in Col A - at which point Col B will be blank - which then finds the relevant SKU wherever you list the Products and SKUs, and pastes it in Col B of the row.

    Ochimus
    Last edited by Ochimus; 12-15-2020 at 08:51 PM.

+ 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] update data based on choosen value from drop down list
    By young_86 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-03-2019, 10:33 AM
  2. [SOLVED] Auto-update cells based on a cell drop-down list and a table
    By Castillb in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-27-2015, 07:19 PM
  3. [SOLVED] Update cell list based on Drop down List
    By eaflynn in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-24-2015, 03:48 PM
  4. Need Macro Code to 'update' drop down list
    By Pencil101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-26-2013, 04:46 AM
  5. [SOLVED] Update respective cell values in the table based on Multiple Drop Down list selections.
    By nileshpatil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-16-2012, 09:30 AM
  6. [SOLVED] Update respective cell value based on Multiple Drop Down list selections
    By nileshpatil in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-16-2012, 08:43 AM
  7. [SOLVED] Update values based on drop down list
    By canadiang8r in forum Excel General
    Replies: 2
    Last Post: 04-13-2012, 10:07 PM

Tags for this Thread

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