+ Reply to Thread
Results 1 to 4 of 4

If Statement in VBA For Loop Not working

  1. #1
    Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    323

    If Statement in VBA For Loop Not working

    I'm trying to create a userform for generating a list of data based on parameters chosen in the userform. The code I am working on atm is below:
    When I use this line everything seems to work fine:
    Please Login or Register  to view this content.
    But when I add another parameter like this is does not find any matches.
    Please Login or Register  to view this content.
    Any help is greatly appreciated!

    Entire Code Segment that is not working
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by unit285; 04-12-2017 at 12:48 PM.

  2. #2
    Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    323

    Re: If Statement in VBA For Loop Not working

    A good way to test is to open the Reports userform and select "CW" from the combobox and then type "Tiller" into the "Search" textbox and then click Generate Report. This searches the database for all CW and then narrows it down to Descriptions that include "Tiller" This seems to work fine. But when i enter an amount into the "Low Price" textbox it finds no matches. The Low Price textbox should narrow the matches to not include any rows of data with an adjusted cost less then the value in the Low Price textbox. Hopefully I am not confusing anyone

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

    Re: If Statement in VBA For Loop Not working

    Assuming the tbLow is a textbox its value is a string so you can't use it directly in a numerical comparison.

    To use the value in such a comparison you need to change it to a number and you can do that with one of VBA's conversion functions,eg Val, CInt etc
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    323

    Re: If Statement in VBA For Loop Not working

    Quote Originally Posted by Norie View Post
    Assuming the tbLow is a textbox its value is a string so you can't use it directly in a numerical comparison.

    To use the value in such a comparison you need to change it to a number and you can do that with one of VBA's conversion functions,eg Val, CInt etc
    Perfect and simple solution! 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. [SOLVED] If Else statement in a loop
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2016, 11:22 AM
  2. For loop within loop not working correctly
    By HalPlz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-25-2015, 12:06 AM
  3. [SOLVED] For Next Loop with IF statement inside does not loop
    By roxybethany in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-09-2013, 11:45 AM
  4. Working While Statement Stops Working
    By Verbaruab in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2011, 05:58 PM
  5. IF Statement loop
    By pkling in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-04-2010, 09:26 AM
  6. If statement - Loop?
    By George in forum Excel General
    Replies: 0
    Last Post: 03-13-2006, 08:20 PM
  7. Help with a loop VBA with an if statement
    By kixelsid in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-28-2006, 03:20 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