Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA trigger enter or update lookup values

Tags:

loops

excel

vba

I have the following code:

Sub PrintToCSV()
    Dim i As Long, e As Long
    i = Worksheets("STATEMENT (2)").Range("$G$6").Value
    e = Worksheets("STATEMENT (2)").Range("$G$7").Value

    Do While i <= e
        Range("K6") = i
        Application.Wait (Now + #12:00:01 AM#)

        If Range("$X$10").Value > 0 Then
            Cells(1, 1).Value = i
        End If

        i = i + 1
    Loop
End Sub

It loops and changes value of Range("K6") as expected. However, the value of Range("K6") updates other cells values (vlookup) when I do it manually, but not with this code. How can I ensure the values of other cells depended on Range("K6") changes with this code?

like image 802
Elen Avatar asked Sep 16 '16 15:09

Elen


Video Answer


1 Answers

Just FYI - do not declare like this:

Dim i, e as Long

because for this declaration only "e" is declared as long and "i" as a variant. This may cause problems somewhere later.enter image description here

The correct way is:

Dim i as Long
Dim e as Long
like image 158
Vityata Avatar answered Nov 08 '22 12:11

Vityata