I created a loop in VBA that should change a variable (j) in the strSql portion of the code. My output columns on the excel sheet are all indentical. That means that the changing variable j is not taken into consideration in the strsql string. Does anybody know how to use a proper changing variable in this case? Thanks in advance
Set rs = New ADODB.Recordset
For j = 1 To 6
strSql = "SELECT COUNT(*) FROM( " & _
"SELECT COUNT(*) as nbp FROM `order` " & _
"JOIN user ON user.id = order.destination_id " & _
"AND DATEDIFF(date_added , register_date) <= j" & _
"GROUP BY destination_id) c " & _
"GROUP BY nbp " & _
"ORDER BY c.nbp ASC ; "
rs.Open strSql, oConn, adOpenDynamic, adLockPessimistic
res = rs.GetRows
rs.Close
For i = 1 To 2
Cells(i, j) = res(0, i - 1)
Next i
Next j
You need to move j out of your string
register_date) <= j” &
To
register_date) <= ” & j &