[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:
If ranInd.Cells(9).Value <> "" Then
Next i
End If
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
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
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:
For X = 1 To 100
If ranInd.Cells(9).Value <> "" Then
'Do normal stuff
End If
Next
Re: Looping - if Cell value is blank go to next i
Quote:
skip the next couple of steps
How are your other range(s) placed? at regular intervals or are they at random places?
Re: Looping - if Cell value is blank go to next i
its two rows down
so i offset(2)
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...
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
Re: Looping - if Cell value is blank go to next i
Quote:
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...
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
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:
range("J2:J3").select
Do Until i = range("B1").value
If ActiveCell.Value = "" Then
Selection.EntireRow.Delete
End If
i = i + 1
Selection.Offset(2).Select
Loop
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