`enter code here`Ok, so basically what this code is supposed to do is;
-start a loop**
-look up values and store them as variables
-put all variables into the 1st listbox
-loop back and
-get new variables and...
-...put in the 2nd listbox
-loop 4 times until all 4 listboxes are complete.
For simplicity I have named the listboxes ListBox1, Listbox2, ListBox3 & Listbox4.
In the With Statement, the Code gives me a 1004 error: unable to get the OLEObjects property out of the worksheet class, which means it can't find it, I guess.
Can anyone see what I'm missing?
Note:
also doesn't work. Is OLEObject only for ActiveX? How would I do this if I'm using form controls (if that's the problem).
Cheers Anyone!
-start a loop**
-look up values and store them as variables
-put all variables into the 1st listbox
-loop back and
-get new variables and...
-...put in the 2nd listbox
-loop 4 times until all 4 listboxes are complete.
For simplicity I have named the listboxes ListBox1, Listbox2, ListBox3 & Listbox4.
In the With Statement, the Code gives me a 1004 error: unable to get the OLEObjects property out of the worksheet class, which means it can't find it, I guess.
Can anyone see what I'm missing?
Note:
Code:
With ActiveSheet.OLEObject("ListBox" & i).Value
also doesn't work. Is OLEObject only for ActiveX? How would I do this if I'm using form controls (if that's the problem).
Code:
'current year predictions
Dim ForecastYear As Double
ForecastYear = Year(Now) + 0.1
Dim i As Integer
Dim Forecast As Double
Dim wForecast As Double
Dim wDemand As Double
For i = 1 To 4 'loop information to place into listboxes for current year's quarterly predictions
'lookup info to place into 1st row of listbox
On Error Resume Next
Forecast = Application.VLookup(ForecastYear, Sheets(ProdCode).Range("A1:S5000"), 10)
On Error GoTo 0
If IsError(Forecast) Then
MsgBox "couldn't find '" & ForecastYear & "' in Sheets '" & ProdCode & "'"
Exit Sub
End If
Forecast = Round(Forecast, 2)
'lookup info to place into 2nd row of listbox
On Error Resume Next
wForecast = Application.VLookup(ForecastYear, Sheets(ProdCode).Range("A9:o5000"), 15)
On Error GoTo 0
wForecast = Round(wForecast, 2)
'lookup info to place into 3rd row of listbox
On Error Resume Next
wDemand = Application.VLookup(ForecastYear, Sheets(ProdCode).Range("A9:m5000"), 13)
On Error GoTo 0
wDemand = Round(wDemand, 2)
ForecastYear = ForecastYear + 0.1 'add, so that next loop finds next quarterly value
'-----------------------------------------------------------------------------
With ActiveSheet.OLEObjects("ListBox" & i).Object 'add current quarterly info to the current listbox
.AddItem ""
.AddItem Forecast
.AddItem ""
.AddItem ""
.AddItem wForecast
.AddItem ""
.AddItem ""
.AddItem wDemand
End With
Next i 'go to next listbox loop
Cheers Anyone!