Results 1 to 12 of 12

Thread: [RESOLVED]Looping - if Cell value is blank go to next i

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Resolved [RESOLVED]Looping - if Cell value is blank go to next i

    Hi,

    I am looping through a list of items and if a certain cell is blank i am to skip the next couple of steps and go to the next item in the loop
    inside the loop i have attempted this, but it wont compile so obviously there is something wrong
    ranInd is a range, so if this value is blank i want to go to the next range

    cheers
    VB Code:
    1. If ranInd.Cells(9).Value <> "" Then
    2.      Next i    
    3.      End If
    Last edited by Mitch_s_s; Feb 3rd, 2007 at 08:00 AM.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Looping - if Cell value is blank go to next i

    you could use a goto (although try to avoid it)

    post the full loop code...so we can see where and how to tweak it
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Looping - if Cell value is blank go to next i

    i'm at home now soi cant post it

    i havent finished the code for the loop

    but i need a way to start the next item

    didnt really want to use go to

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Looping - if Cell value is blank go to next i

    I usually do somthing like this..
    test right off the bat... if its not blank.. do your code.. otherwise it will skip it all

    VB Code:
    1. For X = 1 To 100
    2.     If ranInd.Cells(9).Value <> "" Then
    3.         'Do normal stuff
    4.     End If
    5. Next
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Looping - if Cell value is blank go to next i

    skip the next couple of steps
    How are your other range(s) placed? at regular intervals or are they at random places?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Looping - if Cell value is blank go to next i

    its two rows down
    so i offset(2)

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Looping - if Cell value is blank go to next i

    Hmm, I understand

    Ok, last two questions...

    Does every range have fixed number of cells? for example
    range1= "a1:a5" (say 5 cells)
    then after two rows...
    range2= "a8:a12"
    then after two rows...
    range3= "a15:a19"
    and so on?

    and the 2nd question

    Are then a specific number of ranges for example 5 ranges or 10 ranges?

    Sorry for asking to many questions. It's just that I need to be sure before posting a solution...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Looping - if Cell value is blank go to next i

    no its ok, i appreciate any help so i am happy to answer any questions

    my range is for example
    B2:H3
    then i offset 2

    but before i go into the loop i have put a counta formula in cell B1
    and i then store this as my i for the count, just so i know how many loops there will be
    but not all of these ranges are valid

  9. #9
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Looping - if Cell value is blank go to next i

    my range is for example
    B2:H3
    then i offset 2

    but before i go into the loop i have put a counta formula in cell B1
    and i then store this as my i for the count, just so i know how many loops there will be
    but not all of these ranges are valid
    I am sorry, I didnt get it but
    No I won't ask you more questions...

    is it possible to upload your workbook so that I can understand it more clearly...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Looping - if Cell value is blank go to next i

    I will upload shortly

    say my first range is B2:H3
    My next range would be B4:H5

    i want to be able to skip the range if a certain cell is blank

    and i know the maximum number of ranges i will have as in cell B1 the formula is
    =counta(B2:B1000)
    i then store this value into i(my count)
    and take one off it each time i loop

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Looping - if Cell value is blank go to next i

    This is what i have come up with
    there may be easier ways i dont know....

    VB Code:
    1. range("J2:J3").select
    2. Do Until i = range("B1").value
    3. If ActiveCell.Value = "" Then
    4.     Selection.EntireRow.Delete
    5. End If
    6. i = i + 1
    7. Selection.Offset(2).Select
    8. Loop

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Looping - if Cell value is blank go to next i

    i put the above, before my main loop
    this appears to have fixed it

    let me know if you have any other approaches

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width