Loop counter

Jirka79

New Member
Joined
Dec 9, 2020
Messages
32
Office Version
  1. 2010
Platform
  1. Windows
Hi all,

I'm attaching you an Excel file, which has measurements in sheet DataCam1 and sheet DataCam2. Those measurements, needs to have their own match within both sheets with a maximum desynchronization of 4 seconds. When this condition is not meet, I need to remove the rows that they don't have a match. This means, that row B2 from DataCAm1 needs to have it's match in also row B2 of 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 differences using the sheet "Test". There you can see the times differences between cells 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 appears the line to be deleted. The code delete all the rows of DataCam1 and DataCam2 that are previously shown in the sheet Test.

My question here is that I would like to add 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?

My code is:

VBA Code:
Sub Macro1()
'
' Macro1 Macro
'

'
Worksheets("Test").Activate
Dim strWsName As String
On Error GoTo skip
Do

 strWsName = Range("m1")
 Sheets(strWsName).Select


Dim r As Integer


r = Worksheets("Test").Range("N1").Value
Cells(r, 1).Select

Rows(ActiveCell.Row).Delete

Worksheets("Test").Activate
Loop
Exit Sub
skip: Exit Sub

End Sub

Thanks you all in advance for your support!
 

Attachments

  • Example.JPG
    Example.JPG
    71 KB · Views: 3

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Ok... I have just found a solution:

VBA Code:
Sub Macro1()
'
' Macro1 Macro
'


Worksheets("Test").Activate
Dim Counter As Variant
Dim strWsName As String
On Error GoTo skip
Counter = 0
Do

 strWsName = Range("m1")
 Sheets(strWsName).Select


Dim r As Integer


r = Worksheets("Test").Range("N1").Value
Cells(r, 1).Select

Rows(ActiveCell.Row).Delete

Worksheets("Test").Activate
                Counter = Counter + 1
                ActiveSheet.Range("J4").Value = Counter
Loop
Exit Sub
skip: Exit Sub

End Sub

Now I get the result in cell J4 of 9 rows deleted
smile.gif
Now my next challenge is to know how many of those 9 have been deleted in DataCam1 and how many in DataCam2... any ideas?
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,397
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top