ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Counter does not reset, on 2nd trial (https://www.excelbanter.com/excel-programming/273510-counter-does-not-reset-2nd-trial.html)

Milind

Counter does not reset, on 2nd trial
 
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


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003




All times are GMT +1. The time now is 04:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com