hi,
In module called "total_measures" I have simply code:
The code is working OK.
Now I want to run this code, after I open workbook. So, in "ThisWorkbook" I add code as below:
But something is wrong, because I`m getting wrong numbers.
Please assist.
In module called "total_measures" I have simply code:
Code:
Sub count_total_measures()Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
Set ws = wb.Worksheets("row_data")
Dim x_row_data, i, count_measure As Long
x_row_data = ws.Cells(Rows.Count, "A").End(xlUp).Row
count_measure = 0
For i = 2 To x_row_data
If Range("D" & i).Value <> "" Then
count_measure = count_measure + 1
End If
If Range("E" & i).Value <> "" Then
count_measure = count_measure + 1
End If
If Range("F" & i).Value <> "" Then
count_measure = count_measure + 1
End If
If Range("G" & i).Value <> "" Then
count_measure = count_measure + 1
End If
If Range("H" & i).Value <> "" Then
count_measure = count_measure + 1
End If
ws.Range("C" & i).Value = count_measure
count_measure = 0
Next i
End Sub
The code is working OK.
Now I want to run this code, after I open workbook. So, in "ThisWorkbook" I add code as below:
Code:
Private Sub Workbook_Open()
Call total_measures.count_total_measures
End Sub
But something is wrong, because I`m getting wrong numbers.
Please assist.