+ Reply to Thread
Results 1 to 6 of 6

VBA Code for a loop with a twist

Hybrid View

  1. #1
    Registered User
    Join Date
    02-26-2015
    Location
    RSA
    MS-Off Ver
    2010
    Posts
    29

    VBA Code for a loop with a twist

    Hi,

    On Book1.xlsm there is a product table for company BF with all their products, ranges for each product and colour for each range.

    For spreadsheet "Quotations" you can choose the company, product, range and colour on a dropdown list, as per row 2. The VBA code I wrote only works for row 2, how do I get it so that for each row 2 - 31 a person can input different choices?

    Am not sure how to loop it in this case, because for each row the parameters in row one of the dropdown spreadsheet need to change?

    Thanks
    Last edited by slabs; 01-06-2016 at 06:41 AM. Reason: Fixed incorrect code

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: VBA Code for a loop with a twist

    I don't see anything attached. Based on your description, I recommend assigning the range a name. Make it a named dynamic range. When I see how the data is organized, I might be able to give you a better answer.

  3. #3
    Registered User
    Join Date
    02-26-2015
    Location
    RSA
    MS-Off Ver
    2010
    Posts
    29

    Re: VBA Code for a loop with a twist

    Hi,

    Hopefully the sheet is attached now. Thanks for looking into it.

    Regards

    André
    Attached Files Attached Files

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: VBA Code for a loop with a twist

    I gave this a quick test:
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    ' $c$2 is the Company Dropdown
    ' $d$2 is the Product Dropdown
    ' $e$2 is the Range Dropdown
    
    If Intersect(Target, Range("$C$2:$E$30")) Is Nothing Then Exit Sub
    
    Select Case Left(Target.Address, 2)
        Case "$C"                                                 ' The region dropdown is changed
             Worksheets("Dropdown").Range("$D$1") = Target.Value    ' Set the filter on the company pivot table
        Case "$D"                                                 ' The product dropdown is changed
             Worksheets("Dropdown").Range("$G$1") = Target.Value    ' Set the filter on the product pivot table
        Case "$E"                                                 ' The range dropdown is changed
             Worksheets("Dropdown").Range("$J$1") = Target.Value    ' Set the filter on the range pivot table
        Case Else
            MsgBox "An error has occured", vbOKOnly, "Invalid Selection"
    End Select
    
    End Sub

  5. #5
    Registered User
    Join Date
    02-26-2015
    Location
    RSA
    MS-Off Ver
    2010
    Posts
    29

    Re: VBA Code for a loop with a twist

    Excellent! Much appreciated

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: VBA Code for a loop with a twist

    I don't see any code.

    OK. I see it on the page.

+ 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] How can I make this code shorter by using a loop. or there's any easier shorcuts code
    By romarkevinruiz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-10-2014, 08:53 AM
  2. Loop code to run for each row
    By anfdrew in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-12-2013, 12:47 PM
  3. [SOLVED] How to put the code in a for loop or simplifing the code
    By willy292 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-09-2013, 06:34 AM
  4. Code to turn this code into a loop doing muliple copies
    By fbplaya02 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2013, 12:02 PM
  5. Loop code
    By martinp1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-26-2013, 07:54 AM
  6. Need help with loop code
    By confused in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-19-2006, 02:10 PM
  7. [SOLVED] Code to bold names within a cell- With a twist
    By macro_guy34345 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-15-2006, 12:55 PM
  8. Help with better loop code
    By Sliman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-16-2006, 03:15 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