VBA .resize(ubound(arr)) returning only first value of array

ouvay

Board Regular
Joined
Jun 9, 2022
Messages
131
Office Version
  1. 2019
Platform
  1. Windows
Hello, I have this code ...

VBA Code:
Sub Pivot_Replace()

Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.Worksheets("Batch Processing & Hold List")
Dim salesList As Worksheet: Set salesList = wb.Worksheets("Sales List Import")


Dim lr As Long, i As Long, j As Long, a As Variant, cancel() As Variant

lr = salesList .Cells(salesList .Rows.Count, 1).End(3).Row
a = salesList.Range("A2:R" & lr).Value
ReDim cancel(1 To lr) As Variant

For i = LBound(a) To UBound(a)
    If a(i, 9) <> Empty Then
        j = j + 1
        cancel(j) = a(i, 3)
    End If
Next i

ws.Range("T7").Resize(UBound(cancel)).Value = cancel

End Sub

but when the result I get printed back is only the first position of the array... for example..

if the first value in the array is AAA... the entire range will have just AAA printed back.. and not the actual values..

I can see the whole array successfully calculated in the watch window.. but the return to range bit is bugging out...
any tips?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You have cancel as a single dimension array.
Try putting
= Application.Transpose(cancel)
 
Upvote 0
Solution
In case you are interested, if you Redim as 2 dimension.
ReDim cancel(1 To lr, 1 to 1) As Variant
Load it as
cancel(j, 1) =
Then you won't need the transpose.
Note: transpose has a max and caps out at around 60k records (don't quote me on the number, I am texting from my mobile ;) )
 
Upvote 0
In case you are interested, if you Redim as 2 dimension.
ReDim cancel(1 To lr, 1 to 1) As Variant
Load it as
cancel(j, 1) =
Then you won't need the transpose.
Note: transpose has a max and caps out at around 60k records (don't quote me on the number, I am texting from my mobile ;) )
good to know! I'm currently capping out at 20k rows so I don't think it will come to that anytime soon! thanks for the heads-up though!
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top