Counter does not reset, on 2nd trial

M

Milind

Hello

Though my code runs well, if I run it the second time, though I have issued
the statement "counter=0", it starts from the last used value. The code is
like this:

counter = 0
For Each c In Worksheets("Sheet1").Range("A2:A100").Cells
valie = c.Value
If c.Value = 22381 Then
wala = c.Offset(0, 5).Value
If wala = "pills" Then
milla = c.Offset(0, 2).Value
Call file_write
End If
End If
Next c
counter = 0
End Sub

Sub file_write()
Set wkbk = Nothing
On Error Resume Next
Set wkbk = Workbooks("sample-2.xls")
On Error GoTo 0
If wkbk Is Nothing Then
Workbooks.Open FileName:="C:\milinda\sample-2.xls"
End If

Range("E" & counter + 1).Value = milla
Selection.NumberFormat = "#,##0.00"
counter = counter + 1

End Sub

How to cope with this ?

Milind
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top