Hi. I have developed a workbook which is to be used for data capture and producing xml to run through a Matlab model and receive xml response.
Data will eventually be stored in a database but currently I am posting it into a text file. Every data entry cell in the workbook has a named range so the data exported into these text files will contain the of the named range and value entered.
My issue is when re-importing this data into the form (as the user may need to edit or update it), I transfer from the text file into an array. I am currently populating the named ranges by looping through the array and this works ok but despite all my efforts, the screen flickers around (despite screen updating being false) and I'm worried it might get slow given what the client wants me to do with the workbook. Ultimately, there could be up to 10,000+ named ranges to populate.
So I'm curious whether its possible to get VBA to point to all the named ranges at once and populate with the values in one go rather than looping through the array?
I can get VBA to point to all the cells but can only populate them with a single value (100 in the example below) and not the separate values for each named range/cell.
The code and table below shows a simple example. Any help will be appreciated
The named ranges Range1, Range2, Range3 and Range4 are individual named cells randomly placed in the sheet (i.e. non contiguous)
My data
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]RangeNames[/TD]
[TD]Source[/TD]
[/TR]
[TR]
[TD]Range1[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]Range2[/TD]
[TD]200[/TD]
[/TR]
[TR]
[TD]Range3[/TD]
[TD]300[/TD]
[/TR]
[TR]
[TD]Range4[/TD]
[TD]400[/TD]
[/TR]
</tbody>[/TABLE]
Data will eventually be stored in a database but currently I am posting it into a text file. Every data entry cell in the workbook has a named range so the data exported into these text files will contain the of the named range and value entered.
My issue is when re-importing this data into the form (as the user may need to edit or update it), I transfer from the text file into an array. I am currently populating the named ranges by looping through the array and this works ok but despite all my efforts, the screen flickers around (despite screen updating being false) and I'm worried it might get slow given what the client wants me to do with the workbook. Ultimately, there could be up to 10,000+ named ranges to populate.
So I'm curious whether its possible to get VBA to point to all the named ranges at once and populate with the values in one go rather than looping through the array?
I can get VBA to point to all the cells but can only populate them with a single value (100 in the example below) and not the separate values for each named range/cell.
The code and table below shows a simple example. Any help will be appreciated
The named ranges Range1, Range2, Range3 and Range4 are individual named cells randomly placed in the sheet (i.e. non contiguous)
Code:
Sub CopyPasteFromArray()
Dim arrData() As Variant
Dim arrRanges() As Variant
Dim sRng As String
Dim x As Long
'transfer data to array
arrData() = Range("Source")
arrRanges() = Range("RangeNames")
sRng = ""
For x = LBound(arrRanges) To UBound(arrRanges)
If x = LBound(arrRanges) Then
sRng = arrRanges(x, 1)
ElseIf x > LBound(arrRanges) And x <= UBound(arrRanges) Then
sRng = sRng & "," & arrRanges(x, 1)
End If
Next x
Range(sRng).Value = arrData
End Sub
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]RangeNames[/TD]
[TD]Source[/TD]
[/TR]
[TR]
[TD]Range1[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]Range2[/TD]
[TD]200[/TD]
[/TR]
[TR]
[TD]Range3[/TD]
[TD]300[/TD]
[/TR]
[TR]
[TD]Range4[/TD]
[TD]400[/TD]
[/TR]
</tbody>[/TABLE]
Last edited by a moderator: