Hello everyone.
I am wondering if someone could help me
I am having some issues with this loop:
Kind regards,
Leo.
Hello everyone.
I am wondering if someone could help me
I am having some issues with this loop:
Kind regards,
Leo.
Last edited by LeoExcelRookie; 06-10-2021 at 06:36 PM.
So...You are wanting to jump to the cell directly after the cell with value "SomeValue" ?
No need for loop...
Please Login or Register to view this content.
Last edited by sintek; 06-10-2021 at 01:10 PM.
Good Luck
I don't presume to know what I am doing, however, just like you, I too started somewhere...
One-day, One-problem at a time!!!
If you feel I have helped, please click on the star to left of post [Add Reputation]
Also....add a comment if you like!!!!
And remember...Mark Thread as Solved.
Excel Forum Rocks!!!
Hi,
Thanks for your reply.
I just want to simulate a "Next Cell" process for the CELL variable.
The "some value" is just some random action to happen.
I am struggling on how to make the Cell variable move/jump to the next value inside itself, since it is a Range from I2:I10
Not sure what you mean...Perhaps you should upload a sample file and explain in detail what it is you are trying to achieve...I am struggling on how to make the Cell variable move/jump to the next value inside itself
Hi. Again, thanks for ur reply.
Here is some pseudo code:
Thanks for your reply.
Btw, CT is lovely!
:-)
Last edited by LeoExcelRookie; 06-10-2021 at 06:37 PM.
as per post 1...this code means nothing unless we can understand what it is you are wanting to achieve...Here is some pseudo code:
See Post 4
Again...
Thanks so much...
Code removed
Last edited by LeoExcelRookie; 06-10-2021 at 06:21 PM.
I'm outta here...Sorry...Good luck...Still have not complied with post 4
Ok...
Sorry...
I will upload it...
I thought the code was enough...
You keep on posting code???
Explain in detail what it is you are trying to do...and explain what does this mean...
access the next value inside the Cell variable.
Sorry for the huge delay and many mistakes with posting code here...
Here is the file.
Regards.
Okay, so now we have a sample file...Still have not explained in detail what it is you are wanting to achieve???
See Post 4 and Post 10...
and explain what does this mean...
And Please, do not edit a post after a response has been posted...Now, nothing in this thread makes sense...access the next value inside the Cell variable.
I have a variable called CELL that has values based on a range from A1 to A10.
These values are not Integers, rather, they are strings.
What I am trying to do is to loop through them, which i can do, and when
the loop reaches the fifth element, it "jumps" or "skip" to the
seventh element, ignoring the sixth one. (line 5)
I see that the ForEach loop has a "Next Cell" (line 17) that "moves" to the
next CELL.
What command is similar or can emulate that same "next cell" behavior
so i can "jump" or "skip" to the next Cell?
Regards
Leo
Wow...thank you...Now that makes sense...
Play around with this...
Please Login or Register to view this content.
Thank you and sorry for the previous messy posts.
I have tried that one. But the issue still kind of the same:
How to access the 7th element of the Cell Variable?
Please Login or Register to view this content.
Why would you need to do that? If you don't want to process that cell, don't include it in the range to start with.
Rory
What you mean 7th element...Do you want the code to exit the loop and go to A7???
See attached...
Thanks... I also thought about that. But lets assume I am not able to use that option.
How would I "skip" to the seventh element in the variable Cell ?
Regards
By adapting the code in Post 2...No loop needed...How would I "skip" to the seventh element in the variable Cell ?
Thanks... thats an interesting solution...
But I still have to use the Cell variable since it is inside of the ForEach loop and i cant get rid of the ForEach loop
We have been going around in circles for days ... You still have not been forthcoming with your requirement...But I still have to use the Cell variable since it is inside of the ForEach loop
Use it for what...We are not mind readers????
You don't. You add a test to see if you're processing the 6th item and if so, don't actually do anything. It's generally bad practice to mess with loop variables even if you can (which you can't with a For Each).
Why don't you explain what you are wanting to do and we could offer a solution...
What does this mean...what do you want to do...Cell variable of the ForEach loop
I keep on asking questions but you never respond to them...is it that difficult...You could have had a solution in post 4 already...
You can add your own counter but you might as well just skip the For Each at that point and use a simple for loop:
but I agree with Sintek: you haven't really explained what you want to do with the 7th cell, or why this would ever be necessary.Please Login or Register to view this content.
I am very sorry if i havent been clear with my posts. My apologies.
I will try my best now. :-)
I am assuming that the variable Cell (For Each Cell In Worksheets("mine").Range("A1:A20"))
is a variable type Array or similar, and, inside it, values, listed from A1 to A20,
are stored -they are just a list of names.
So, since my premisse is that Cell is an array, or similar, when its index reaches
number 5, considering it started from 1, i want to "move" it to index 7, skiping the 6th element
and let the ForEach loop finish its job -whatever it is-.
Again, thank you both for your help.
so all you want to do is loop the cells in Range("A1:A20")
If it gets to the 6th cell, it must skip it and then move on to 7
No, cell is literally one cell (a Range object)
Yup, thats the idea...
:-)
Oh...
So that was my mistake since the very beggining...
A false premisse led me to an error... as usual.
:-)
That is what post 14 does...Yup... Thats the idea...
@sintek & @rorya, gentlemen I must congratulate you on your perfect display of composure.
torachan.
@ Torachan...
Red wine...lots and lots of red wine....
images.jpg
Thank you so much!
Very kind of you all!
PVT me a msg so i can send you a Post Card from Brazil.
Kind regards!
Leo.
But, then again... The idea is to use only the ForEach with the Cell variable and not a For loop.
:-)
So...is your issue solved?
Actually, no.
Since i HAVE to use the ForEach loop and the Cell variable. Cant use a For loop.
Thats why i was insisting with the Cell variable as an array -which was my mistake since the start-
I am about to give up and open a beer... since someone here is drinking wine.
So what happened to
Don't you get it...Explain in layman's terms what you want to do...Yup... Thats the idea...
That is what post 14 does...
Such as ... I want to run a code snippet that loops through a specific range...During that loop, I want to find criteria "X" when it finds that criteria, it must do the following blah blah blah and then carry on with the loop......................................................
Otherwise, there is just NO HOPE FOR A SOLUTION...I mean come on...40 post and still no clue what you want to do!!!
Last edited by sintek; 06-11-2021 at 02:09 PM.
Ok.
Let me use the Layman approach.
I would like to loop through a list of names, located between A1 and A10, using the FOREACH loop, and only that loop.
When i reach the FIFTH cell or the value of A5 from the CELL variable, i would like to jump to A7 inside that same CELL variable.
Please Login or Register to view this content.
Like I said...Post 14 does that...!!!
Step through this code and you will see what I mean...
Please Login or Register to view this content.
Last edited by sintek; 06-11-2021 at 02:59 PM.
So...Solved...Yes
Oh please, oh please do share...The issue was finally solved.
LOL
Well... I removed 60% of the code.
Did a lot of refactoring and "combined" the "Foreach" with an "outside" variable so i could access the values in a way that the Foreach wasnt allowing me.
:-)
Again, thanks a lot...
In few words, i used your example in my "new code".
So...Not prepared to share your full code so others too...can learn...
I can... not a problem... Its that it is quite messy, and i was embarrassed... but here it goes... :-)
Please Login or Register to view this content.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks