Hi all!
I have this code:
And I wonder if I could pop up a msgbox saying how many times the loop has been executed. Is this possible?Please Login or Register to view this content.
Thank you in advance!
Hi all!
I have this code:
And I wonder if I could pop up a msgbox saying how many times the loop has been executed. Is this possible?Please Login or Register to view this content.
Thank you in advance!
Last edited by thorblow; 06-25-2021 at 05:26 PM.
Try it like this
Please Login or Register to view this content.
What are you trying to do? Generally speaking, you don't have to select anything to perform an action on it. So, you don't need to select a sheet to delete a row in it. And you don't need to select a cell to make it the active row in order to delete it.
Where have you got this code? It's certainly not a recorded macro.
But, to answer your question, just define a variable and increment it every time you go through the loop. Remove the Exit Sub before the skip label, and put your MsgBox before the Exit Sub after the skip label.
Trevor Shuttleworth - Retired Excel/VBA Consultant
I dream of a better world where chickens can cross the road without having their motives questioned
'Being unapologetic means never having to say you're sorry' John Cooper Clarke
@maniacb: your MsgBox can never be executed … the code will never get there.
Hi TMS, I was about to answer the same to maniacb...
Regarding the code, here I attach the Excel file. I just did it by my own and it does what I need... I'm not an expert of vba, I just look for some solutions on the internet and put it together :D
Could you please rewrite the code adding the define a variable and increment it every time you go through the loop. Remove the Exit Sub before the skip label, and put your MsgBox before the Exit Sub after the skip label.? I can't do that on my own... :/
TMS, you're right. I put the Msgbox in the wrong spot. It should be after the line 'Loop'
Hi maniacb... I have just try it putting the msgbox after the line loop and still doesn't work... I have added the file so you can check it if you please...
Thanks!
I think what you want to do is delete rows if the times don't match within 4 seconds. I wrote code that will do that instead of trying to get yours to work. Let us know if this is or is not what you want.
Please Login or Register to view this content.
Hi maniac! Thanks for this proposal, but please, note that yes, I delete the rows when the time difference is bigger than 4 seconds, but I delete the rows either in sheet datacam1 or in sheet datacam2, depending where is going to be the next time difference. I never delete the rows in sheet Test. I use the sheet test only as a work sheet for the macro itself and I expect to see the results in the sheets datacam1 and datacam2
Here is an option that bypasses the use of the test sheet. It deletes the smaller value line from datacam1 or datacam2 when the time difference is less than 4 seconds. I then see that the data is not aligned, but maybe that is what you want. Test it out. Let me know how it fares.
Please Login or Register to view this content.
Hello maniacb, sorry for my late reply!!
No, this code is not doing the same as my code.
The goal here is that DataCam1 and DataCam2 has some desynchronization and I need to remove all that values that they don't have a match. This means, that row B2 from DataCAm1 needs to have it's match in also row B2 in DataCam2 within 4 seconds max difference. When this condition is not meet, the time that doesn't have a direct match needs to be removed.
In order to know the value to be removed, I calculate the time difference between time B2 and B3 of DataCam1 and then I compare it with the time difference of also cells B2 and B3 of DataCam2. If the time difference is more than 4 seconds, then deletes the lowest time.
Of course my code needs the help of the formulas shown in the Sheet "Test" because I'm not that good to make all in one with just one code, but I'm happy to see that my code works and does precisely what I need, the only thing I would like to add is a loop counter to know how many rows I have deleted in total. And still would be more nice to know how many rows I have deleted in DataCam1 sheet and how many rows I have deleted in DataCam2.
So, is there a way to add the loop counter as it is in my excel file or using a totally diferent code?
Thanks again for your support!
OK, it was easier than I thought, I have just found the right code:
Now I get the result in cell J4 of 9 rows deleted Now my next challenge is to know how many of those 9 have been deleted in DataCam1 and how many in DataCam2... any ideas?Please Login or Register to view this content.
Try this option. J6 is CAM1 and J8 is CAM2.
Please Login or Register to view this content.
Thanks a lot maniacb! It worked
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks