+ Reply to Thread
Results 1 to 8 of 8

how co i use select case to change cell location in this formula in vba code

  1. #1
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    how co i use select case to change cell location in this formula in vba code

    Im currently using this code to change where the formula looks for data depending on the value in a combobox. Is there a way to simply change the a, a2 and a3 to k, k2 and k3? I tried using an interger like i = a if case is 1 and i=k if case is 2 but cant get it to work.

    Please Login or Register  to view this content.
    Last edited by kevinu; 06-15-2018 at 01:39 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: how co i use select case to change cell location in this formula in vba code

    Are you doing this with an ActiveX Control? I think your on the right track and here is a small sample that looks to the cells in columns A, B, or C to get the value for a formula and used on a change event to see it.

    In worksheet module
    Please Login or Register  to view this content.
    And in normal module to make the combobox
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by ptmuldoon; 06-15-2018 at 02:56 PM.

  3. #3
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    Re: how co i use select case to change cell location in this formula in vba code

    I'm using controlbox1_change() to trigger this code. I'm not sure how to implement your suggestion however. My code puts a formula in a cell. I want to change the formula and i dont know how to do that with what your suggesting. From what I understand if i make a case where x= range("a2"), the code is placed in the cell it will just read x in stead of a2. Unless im misunderstanding what your suggesting. How does the formula know im asking it to look for the range instead of assuming the variable is the range.

    Example, in this code would i switch this

    Please Login or Register  to view this content.
    to this?

    Please Login or Register  to view this content.

    or do i need to put x in between quotes or something so it knows to look up x

    Sorry, im just confused.
    Last edited by kevinu; 06-15-2018 at 04:42 PM.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: how co i use select case to change cell location in this formula in vba code

    Example
    Please Login or Register  to view this content.
    I think it should be like
    Please Login or Register  to view this content.
    Last edited by jolivanes; 06-15-2018 at 04:57 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: how co i use select case to change cell location in this formula in vba code

    i was confused by your initial question and tweaked the code a little to place a formula in the cell based on the drop down value. And I look more tonight when back home on your actual formula.

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: how co i use select case to change cell location in this formula in vba code

    kevinu

    There is no need to duplicate your code within each Case condition. What I am/was doing was just setting what the cell address needs to be based on the combobox selection. Then after the select, you can just insert that variables value into your formula.

    This changes the A3 to X3 in your formula. But note I took a quick shortcut with your additional MyCriteria.Address. If you could post a sample file, we could make this a little cleaner.

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    Re: how co i use select case to change cell location in this formula in vba code

    the formula isnt duplicated. one is + and the other is * in the middle. im looking at a data set that has 2 variables and comparing it to a list of 2 variables. The first code looks to see if any variable from the data set is in the list. The second formula looks if the 2 variables appear anywhere on the list. So more focused. I'll place an example if i can tomorrow. Thx for the help

  8. #8
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    Re: how co i use select case to change cell location in this formula in vba code

    PT, that worked like a charm thanks

+ 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. Macro code change based on cell location
    By krekeris in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-21-2015, 06:41 AM
  2. [SOLVED] [Help]macro to open file browser, to select a location, and save the location to a cell
    By zhuleijia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2013, 09:56 AM
  3. [SOLVED] Disregard case in VBA code. (UCase, LCase, Select Case)
    By Orestees in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-07-2012, 12:12 PM
  4. [SOLVED] How to improve SELECT CASE or how to change this???
    By VBAxxx in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-24-2012, 07:46 PM
  5. How to change a variable using select case
    By ref in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-16-2012, 11:59 AM
  6. Replies: 6
    Last Post: 08-10-2011, 07:19 AM
  7. Select Case code not executing macro on Dropdown (change)
    By 4am in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-10-2010, 02:32 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