+ Reply to Thread
Results 1 to 13 of 13

Case Statements and If Statements

  1. #1
    Registered User
    Join Date
    09-04-2012
    Location
    Reno, NV
    MS-Off Ver
    Excel 2010
    Posts
    6

    Case Statements and If Statements

    Hello and thank you in advance for any help!

    I am compiling a dataset from 2 databases. One of the databases exports a data field "A". The other exports a data field as the product of "A" and a payment rate. I am trying to have the final dataset only report "A", so I need to divide "A" out of the field that is the product of "A" and the payment rate.
    The payment rate is based on 4 primary categories:

    Region = North, South
    Program = Solar, Wind, Hydro, Solar Thermal
    Category = Residential, Small Business, Public, Agriculture
    Step = 1,2,3,4,5,6,7,8,9

    I have set up a table that has the Step in a column, and the other descriptors in the rows. I was able to create a nested If statement formula and copy/paste it down the column for some of the combinations, but am limited by the number of If statements. So, I am trying to use VBA to divide the value in column 12 (the product of "A" and the payment rate) by the payment rate to obtain "A", based on which combination of descriptors describes the project.

    Below is a sample of the road I was trying to go down, without initial success. Again, any help is GREATLY appreciated!

    Please Login or Register  to view this content.
    Thanks, JM

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Case Statements and If Statements

    Hi hawsoon13,

    You need "=" before your formulas:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    09-04-2012
    Location
    Reno, NV
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Case Statements and If Statements

    Thanks xladept, now I get a Run-time error 1004: Application-defined or object-defined error.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Case Statements and If Statements

    you are mixing a1 style references and r1c1 references

    also what is mergeprocess! supposed to be?

    additional point-you seem to be using the same formula in both cases so you may as well put them into one case statement
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Case Statements and If Statements

    You'd have to post an example before we could check out your vlookup.

  6. #6
    Registered User
    Join Date
    09-04-2012
    Location
    Reno, NV
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Case Statements and If Statements

    I cleaned up the "mergeprocess" to "mergeprocess!$p$6:$u$19", as it is the table range used for the vlookup. That table is in a different worksheet named "mergeprocess".
    In this case, the residential and small business cases are the same, so I'll combine.
    Thanks.

    Is mixing reference styles not allowed?

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Case Statements and If Statements

    no not in the same formula. and as you're using the formular1c1 property you need to use r1c1 references everywhere

  8. #8
    Registered User
    Join Date
    09-04-2012
    Location
    Reno, NV
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Case Statements and If Statements

    9-4-12_HelpRequest.xlsm
    Okay, I'll clean that up as well. Thank you all so much!!
    I've attached a sample of some of the data and the vba for your review.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Case Statements and If Statements

    Column "B" in all data is null all the way down????

  10. #10
    Registered User
    Join Date
    09-04-2012
    Location
    Reno, NV
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Case Statements and If Statements

    Column B, in this instance, is used to determine whether or not a specific project "i" has been granted a variance that would show up on the SchoolsPetition table. If it has, then that is the number to be used instead of the calculated cap.

    I hope that makes sense, and I really appreciate the help.

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Case Statements and If Statements

    I reckon
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    09-04-2012
    Location
    Reno, NV
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Case Statements and If Statements

    JosephP, I think this puts me on the right track, so I'll keep developing to cover all combinations.
    A couple of questions though before I start.

    First, how does the code you provided know which workbook/worksheet to act upon? (Probably one of the most basic questions you'll be asked, but as advertised, I am quite new to this)

    Second, for the other programs, do I just need to follow with "ElseIf" statements for each program and follow your lead on the ensuing case statements? Then, an "Else" for the other Utility and the same process for the other programs under that utility?

    Finally, thank you so much again for all your help! I am astounded at the skills of the people on this forum and greatly appreciative!!

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Case Statements and If Statements

    1 it acts on the active sheet
    2 yes that's correct. it might be possible to simplify the code if you created a lookup table of the various combinations or you can continue as you are
    3 you're welcome :-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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