+ Reply to Thread
Results 1 to 23 of 23

Two If Then Statement not working - Excel VBA

  1. #1
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Two If Then Statement not working - Excel VBA

    Most of my If Then Statements are working except two.

    The first If Then Statement is the following. (The 'Intvw_Type" is a combobox with an option of Internal/Informal.)

    Please Login or Register  to view this content.
    The other If Then Statement is the following, which is saying if those two answers are identicle, then put ****** AH:

    Please Login or Register  to view this content.
    Both parts of those two IF Then Statements are working, as you can see in the attached screenshot.

    Weekly Visitor's List IF Then Statement.jpg

    The next part that happens is within this code when the final out put is printed it is placed in a specific spot on a form that is printed out:

    Please Login or Register  to view this content.
    But, this part of the code doesn't seem to be working, but I've checked everything. The cells N42, N33, and N34 are correct. The 33, 34, and 35 are also correct, but the form prints without the correct ****** in N42, N33, and N34.

    I have other If Then Statements that do the same thing, add ****** to their respective cells, however, these two above are not working. Any ideas?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Two If Then Statement not working - Excel VBA

    Have you stepped through the code with F8?

    If you do that you can check the values being used in the code.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    I've not heard of that before. This is new to me. How do I step through the code with F8?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Two If Then Statement not working - Excel VBA

    Try this.

    Select the first if statement, press F9.

    That creates a breakpoint.

    Now do whatever you have to do for the If statements to get executed.

    If you do that the code should then halt and you can step though each line with F8.

  5. #5
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    I'm not getting this. It seems like it should be straight forward but it jumps from this to that and form that to this and it's not making any sense. I know the problem exists somewhere in the second part since the correct answers are placed in the CandidateData worksheet, but are not being transferred to the form.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Two If Then Statement not working - Excel VBA

    What jumps from 'that to this'?

  7. #7
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    Well, I have my curser at the beginning of the line of code I want to test and press F8 and it takes me to Private Sub UserForm_Initialize () each and every time. then, F8 just takes me line thru line for that set of code and then brings up my form....

  8. #8
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    Here is the attached UserForm, maybe this will help shed some light. I've been wracking my brain over this.

    ComboBoxPrintBox_TroublesV9.xlsm

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Two If Then Statement not working - Excel VBA

    You start the userform as you normally would.

    Then you do what you have to for the If statements to be executed.

    The code should then 'break' where you set the breakpoint.

    It's from that point you step through with F8.

  10. #10
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    I haven't been able to figure this out. I'm completely stumped and pulling my hair out on this one. I've double, triple, and quadriple checked everything.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Did you step through the code?

  12. #12
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    That's what I've been pulling my hair just trying to figure out.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Do you mean you haven't been able to step through the code?

    Where did you add breakpoints?

  14. #14
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    I have not been able to step through the code and get any valuable information.

    Breakpoints.jpg

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Two If Then Statement not working - Excel VBA

    Where do you have this code?

  16. #16
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    It's under the print userform. Because the if then statement is working and doing it's job, it's the part from there to where it goes onto the form where the problem is.

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Two If Then Statement not working - Excel VBA

    Those 2 if statements don't look to me as though they belong in the print form.

    The reason I say that is because I think they are actually meant to be writing to the candidate sheet.

  18. #18
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    The two if then statements do write to the candidatedata sheet, and that is the part that works. The part that isn't working is when the print button places the answers from the candidatedata sheet, they don't carry over to the candidateform sheet when printed.

  19. #19
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Two If Then Statement not working - Excel VBA

    So the If statements work perfectly fine?

    Is it this code that doesn't work?
    Please Login or Register  to view this content.

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Two If Then Statement not working - Excel VBA

    The code is working.

    On CandidateForm goto N33, N34 and N33 and change the formatting so you can actually see what's in the cells.

  21. #21
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    Oh my gosh! Seriously! I've been wracking my brain over that, too! Sometimes the simplist things get overthought. Thank you so much! This is crazy and embarrasing. Ugh! Well, it's not because I didn't know what I was doing, huh!? .... I hang my head in shame....

  22. #22
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Two If Then Statement not working - Excel VBA

    No problem.

    Might be worth going through that candidate form checking everything will be visible.

  23. #23
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Two If Then Statement not working - Excel VBA

    Good Idea. I have no idea how and when that formatting changed, but I'm going to go through and fix it all now

+ 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