I appreciate this is an amateurish question but I am not used to VB and its syntax.
I am trying to pull across information from one worksheet (ProductList) to another (Quote) based on whether or not there is a value in the quantity (QTY) column.
Here is my method:
Private Sub cmdProductListContinue_Click()
'Declare variabless
Dim i, duration, qty, outputX, outputY
'Set initial values
duration = 120 'Used to determine number of iterations in for loop (no. of QTY cells we are to check)
i = 3 'Used as cell co-ordinates to pull information from
outputX = 17 'Used as cell co-ordinates to output information
'Populate invoice with product info by iterating through all QTY cells and pulling across info if needed
For i = 3 To duration
'Reset quantity to zero each time
qty = 0
'Set quantity to the value in the QTY cell
Set qty = Worksheets("ProductList").Cells(i, 3)
'If there is a quantity value present
If qty > 0 Then
'Insert quantity value into appropriate cell in quote sheet
Worksheets("Quote").Cells(outputX, 2) = qty
'Insert description into quote sheet
Worksheets("Quote").Cells(outputX, 3) = Worksheets("ProductList").Cells(i, 2)
'Insert unit price into quote sheet
Worksheets("Quote").Cells(outputX, 4) = Worksheets("ProductList").Cells(i, 4)
'Increment the output co-ordinates to the next line
outputX = outputX + 1
End If
Next i
'Open quote sheet
Sheets("Quote").Select
End Sub
Using breakpoints I can see that when there is a quantity value it successfully moves onto the first 'Then' statement but then seems to just return to the start of the loop, missing out the other two output lines completely.
Is my syntax correct? Am I missing something in my logic?
I appreciate it may be hard to think this through without having the sheets to see the data columns etc.
'i' is set to 3 as the Quantity column first value is in cell C,3 with the description in C,2 and price in C,4. These are then incremented through the loop.
Any help with this would be appreciated.
Thanks!!
outputX = outputX + 1appear to execute? I ask because you only mention "missing out the other two output lines completely." Which doesn't include the increment of outputXqty = CInt(Worksheets("ProductList").Cells(i, 3).value)