+ Reply to Thread
Results 1 to 12 of 12

Set dim with if statements

  1. #1
    Registered User
    Join Date
    10-10-2014
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    37

    Set dim with if statements

    Hi,

    I am attempting to set a declared dim inside an if statement and obviously not doing it correctly, declaring "inv1" multiple times is not the solution but the code below should show what i am trying to achieve. Any advice would be great.

    Thanks,
    SPM

    Please Login or Register  to view this content.
    Last edited by silkpantsman; 10-07-2015 at 12:29 PM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Set dim with if statements

    Just put the Dim at the top of the sub

  3. #3
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,915

    Re: Set dim with if statements

    Please Login or Register  to view this content.
    BSB

  4. #4
    Registered User
    Join Date
    10-10-2014
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    37

    Re: Set dim with if statements

    Yeah that is what i did first time around and thought i was losing my nut when it was not working. So i am assuming the problem lies in the rest of my code. I get an application defined or object defined error.

    Please Login or Register  to view this content.
    Last edited by silkpantsman; 10-07-2015 at 06:22 AM.

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

    Re: Set dim with if statements

    Do you have variables named AT, DE and BE etc or are you checking for the strings 'AT', 'DE' and 'BE'?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    10-10-2014
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    37

    Re: Set dim with if statements

    Your correct i should have been using "AT" etc as i am checking for a string, ty. I am still getting same error.

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

    Re: Set dim with if statements

    Where do you get the error?

  8. #8
    Registered User
    Join Date
    10-10-2014
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    37

    Re: Set dim with if statements

    When i run code from VBA menu run time 1004 application defined or object defined error.
    Attached Files Attached Files
    Last edited by silkpantsman; 10-07-2015 at 07:21 AM.

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

    Re: Set dim with if statements

    When I run the code in the workbook I do get an error but not the one you describe.

    However if I replace the code in the workbook with the code I posted in post #5 the code runs without error.

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Set dim with if statements

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

  11. #11
    Registered User
    Join Date
    10-10-2014
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    37

    Re: Set dim with if statements

    Quote Originally Posted by Kyle123 View Post
    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
    Apologies, wont happen again...thanks for the help.

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

    Re: Set dim with if statements

    Nice.

+ 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] Nested if statements containing multiple and statements
    By John M. in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-22-2014, 11:48 PM
  2. Formula with multiple IF statements and IF AND statements
    By lottidotti in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-14-2013, 08:03 AM
  3. Reading If statements and formulating values from if statements
    By crnam in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-16-2013, 05:20 AM
  4. questions with if statements and nested if statements
    By Pat Excel in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 02-03-2013, 01:41 PM
  5. Nested If statements / logic statements
    By Brainless_09 in forum Excel General
    Replies: 3
    Last Post: 06-17-2009, 02:59 PM
  6. Replies: 12
    Last Post: 05-15-2009, 08:38 AM
  7. [SOLVED] operator statements, shorting when reusing one of the statements?
    By KR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2005, 02:05 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