JONABRA
New Member
- Joined
- Mar 15, 2019
- Messages
- 19
Greetings
I'm fairly new to VBA and finally require some assistance, as I can't seem to find this question on any of the forums
I have a sheet with multiple columns, but only need a select few. I recently came across a method to paste an entire column in an array with a line of code that looks like this : relevantcols(1) = oldsched.Range("cp1:cp" & lrowoldsched) etc. In the example of code I provided below I only need 3 specific columns placed into the array. The issue arises when attempting to paste the entire array back into the worksheet. Am I able to paste all 3 columns with one line of code back into the worksheet?
I tried utilizing the resize function like this:
Worksheets("arrays").Range("m1").Resize(rowcount, colcount).Value = relevantcols
I got the rowcount and colcount using this:
however the only way I can paste it back is using a for loop as seen below. What kind of array am I working with here an why can't I paste the entire array in one line of code?
when using the watches window the array looks like this relevantcols(1)(1,1) and so on
Much Thanks
I'm fairly new to VBA and finally require some assistance, as I can't seem to find this question on any of the forums
I have a sheet with multiple columns, but only need a select few. I recently came across a method to paste an entire column in an array with a line of code that looks like this : relevantcols(1) = oldsched.Range("cp1:cp" & lrowoldsched) etc. In the example of code I provided below I only need 3 specific columns placed into the array. The issue arises when attempting to paste the entire array back into the worksheet. Am I able to paste all 3 columns with one line of code back into the worksheet?
I tried utilizing the resize function like this:
Worksheets("arrays").Range("m1").Resize(rowcount, colcount).Value = relevantcols
I got the rowcount and colcount using this:
Code:
rowcount = UBound(relevantcols(1)) - LBound(relevantcols(1)) + 1
colcount = UBound(relevantcols) - LBound(relevantcols) + 1
however the only way I can paste it back is using a for loop as seen below. What kind of array am I working with here an why can't I paste the entire array in one line of code?
VBA Code:
Dim relevantcols() As Variant
Dim tpmt, oldsched As Worksheet
Dim lrow, lrowoldsched, counter, i As Integer
Set tpmt = Worksheets("Third Party & M-Net Merged")
Set oldsched = Worksheets("SSCCatchUpScheduleRpt")
relevantcols(1) = oldsched.Range("cp1:cp" & lrowoldsched)
relevantcols(2) = oldsched.Range("ct1:ct" & lrowoldsched)
relevantcols(3) = oldsched.Range("cs1:cs" & lrowoldsched)
For x = 1 To 6
Worksheets("arrays").Cells(1, x).Resize(rowcount).Value = relevantcols(x)
Next x
when using the watches window the array looks like this relevantcols(1)(1,1) and so on
Much Thanks