Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Loop Help Please

Loop Help Please

Scheduled Pinned Locked Moved Visual Basic
questionhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harveyhanson
    wrote on last edited by
    #1

    I am trying to do this loop, so it checks if a value entered is present, if not, it deletes the row, however, the process hangs once it finishes, how do i end the statement (i.e. when all records have been checked, display a message box), as I am not sure where to end it (I thought the end if and wend would end the statement, but do I possibly need an else somewhere?), cheers p.s. this is VBA in excel 2003, but I assume its the same principal as VB ---- 'When a cell contains data, perform the IF... While Len(Range("B" & CStr(LFindRow)).Value) > 0 'If the cell does not contain the inputted criteria then delete the row If Range("B" & CStr(LFindRow)).Value <> CustVar Then Rows(CStr(LFindRow)).Delete 'End the IF End If 'End/Loop the while Wend ----

    L S 2 Replies Last reply
    0
    • H harveyhanson

      I am trying to do this loop, so it checks if a value entered is present, if not, it deletes the row, however, the process hangs once it finishes, how do i end the statement (i.e. when all records have been checked, display a message box), as I am not sure where to end it (I thought the end if and wend would end the statement, but do I possibly need an else somewhere?), cheers p.s. this is VBA in excel 2003, but I assume its the same principal as VB ---- 'When a cell contains data, perform the IF... While Len(Range("B" & CStr(LFindRow)).Value) > 0 'If the cell does not contain the inputted criteria then delete the row If Range("B" & CStr(LFindRow)).Value <> CustVar Then Rows(CStr(LFindRow)).Delete 'End the IF End If 'End/Loop the while Wend ----

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, there is a flaw in the logic: when Len is > 0 and the IF fails, the while will loop forever. You should consider a while without if, i.e. AND together the two conditions in the WHILE. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


      1 Reply Last reply
      0
      • H harveyhanson

        I am trying to do this loop, so it checks if a value entered is present, if not, it deletes the row, however, the process hangs once it finishes, how do i end the statement (i.e. when all records have been checked, display a message box), as I am not sure where to end it (I thought the end if and wend would end the statement, but do I possibly need an else somewhere?), cheers p.s. this is VBA in excel 2003, but I assume its the same principal as VB ---- 'When a cell contains data, perform the IF... While Len(Range("B" & CStr(LFindRow)).Value) > 0 'If the cell does not contain the inputted criteria then delete the row If Range("B" & CStr(LFindRow)).Value <> CustVar Then Rows(CStr(LFindRow)).Delete 'End the IF End If 'End/Loop the while Wend ----

        S Offline
        S Offline
        soporificeffect
        wrote on last edited by
        #3

        I think your problem is that if there is data in the cell but it doesn't match the value you don't go to the next row. try increasing LFindRow good luck

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups