Hello all,
I have the following problem:
I got a table with 15 columns that are updated from a SQL source.
There are 10 other columns that contain manual values those I want to save to a collection, update the data from the SQL source and then retrieve the values.
My code looks like this:
It does not work though. When I want to check if the values are saved to an array (see the test bit), I get an error.
When I try to retrieve values (and there certainly are values in the ranges I want to save) I dont get any values.
Anyone with help to my problem?
I have the following problem:
I got a table with 15 columns that are updated from a SQL source.
There are 10 other columns that contain manual values those I want to save to a collection, update the data from the SQL source and then retrieve the values.
My code looks like this:
Code:
Sub SaveDataToCollection()
Dim sRange As Range, PKNrs As Range, sCell As Range
Dim i As Long, test() As Variant
Set ws = ThisWorkbook.Sheets("1")
Set gcolCells = New Collection
Set PKNrs = ws.Range(ws.Cells(2, PKNrCol), ws.Cells(1, PKNrCol).End(xlDown))
For Each sCell In PKNrs
If sCell.Row > ws.UsedRange.Rows.Count Then Exit For
Set sRange = ws.Range(ws.Cells(sCell.Row, StartCol), ws.Cells(sCell.Row, EndCol))
gcolCells.Add Item:=Array(sRange), Key:=CStr(sCell.Value)
test = sRange
For i = 1 To UBound(test)
Debug.Print test(i)
Next i
Next sCell
End Sub
Code:
Sub RetrieveDataFromCollection()
Dim sRange As Range, PKNrs As Range, sCell As Range
Set ws = ThisWorkbook.Sheets("1")
Set PKNrs = ws.Range(ws.Cells(2, PKNrCol), ws.Cells(1, PKNrCol).End(xlDown))
For Each sCell In PKNrs
If sCell.Row > ws.UsedRange.Rows.Count Then Exit For
Set sRange = ws.Range(ws.Cells(sCell.Row, StartCol), ws.Cells(sCell.Row, EndCol))
sRange.Value = Application.Transpose(gcolCells.Item(CStr(sCell.Value)))
Next sCell
End Sub
It does not work though. When I want to check if the values are saved to an array (see the test bit), I get an error.
When I try to retrieve values (and there certainly are values in the ranges I want to save) I dont get any values.
Anyone with help to my problem?