Hello
The code below writes a range("M5:V44") to another sheet in one row.
I have trouble getting the data back to the same range as it came from.
----------------------------
I can get the values back in an array and they are always in column 46-445.
But in the array they are stored as arr(1,1) to arr (1,400) and i belive that is one dimensional.
How can i write them out to range ("M5:V44") "it's 10 columns and 40 rows"
The code below writes a range("M5:V44") to another sheet in one row.
I have trouble getting the data back to the same range as it came from.
VBA Code:
Sub writeRange()
r = 1 ' row with ID
k = 46 ' column in the destination sheet
id = shKerneOplysninger.Range("C4").Value
Dim rg As Range
Set rg = shKerneOplysninger.Range("M5:V44")
Dim arr As Variant
arr = rg.Value
Do While shKerneData.Cells(r, 1).Value <> ""
If shKerneData.Cells(r, 1).Value = id Then
For i = LBound(arr) To UBound(arr)
For j = LBound(arr, 2) To UBound(arr, 2)
shKerneData.Cells(r, k) = arr(i, j)
k = k + 1
Next j
Next i
End If
r = r + 1
Loop
End Sub
----------------------------
I can get the values back in an array and they are always in column 46-445.
But in the array they are stored as arr(1,1) to arr (1,400) and i belive that is one dimensional.
How can i write them out to range ("M5:V44") "it's 10 columns and 40 rows"
VBA Code:
Sub getRange()
r = 1 ' Row with ID
id = shKerneOplysninger.Range("C4").Value ' Prøvenummer
Dim arr As Variant
Dim rg As Range
Do While shKerneData.Cells(r, 1).Value <> ""
If shKerneData.Cells(r, 1).Value = id Then
Set rg = shKerneData.Range(Cells(r, 46), Cells(r, 445))
arr = rg.Value
End If
r = r + 1
Loop
End Sub
Last edited by a moderator: