lundi 14 mai 2018

Excel-VBA-The first part of the IF-Else statement with the variable does not answer

I have a VBA code for a button to increase value of cells in turn in excel. code is this:

Dim current_row As Long '<-- global variable Current Row
Sub Button6_Click()
    current_row = Sheets("Sheet2").Cells(1, 1)
    If Sheets("Sheet1").Cells(current_row, 7) = 0 Then
        Sheets("Sheet1").Cells(18, 1) = 555555
        current_row = 11  '<-- return to first record row at the end of table-end of table has 0 value
    Else
        current_row = current_row + 1 '<--increases of 1 each click
    End If
    Sheets("Sheet1").Cells(current_row, 7) = Sheets("Sheet1").Cells(current_row, 7) + 1
    Sheets("Sheet2").Cells(1, 1) = current_row
    Sheets("Sheet1").Cells(17, 1) = current_row
End Sub

in first part of IF clause when I use current_row, condition is never true (However,value of current_row changes correctly, and I've added a command for the temporary display current_value that displays correct in cell row 18 and column 1 ) but when I write a number instead of current_row variable and target cell has zero value, first of IF is true and continue correctly. this code apply for a table like this:

+=============+========================+
| **Name**    |**Number of tasks done**|
+=============+========================+
| Joe         |                      3 |
+-------------+------------------------+
| John        |                      2 |
+-------------+------------------------+
| Emma        |                      1 |
+-------------+------------------------+
| Sophia      |                      1 |
+-------------+------------------------+
|End of Table |                      0 |
+-------------+------------------------+

Can you say whats the problem, please?

Aucun commentaire:

Enregistrer un commentaire