Why doesn't this syntax write anything to Sheet 1?

GeeWhiz7

Board Regular
Joined
Nov 22, 2021
Messages
214
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi Folks,
I have an array that I'm trying to write to Sheet 1 of a workbook, but nothing happens and there is no error.
It's a macro with a bunch of company references so hopefully the following snippet is enough to get some insight from somebody more knowledgeable.
When I check the array contents in locals, the values are there, but it looks like the section with resize...=dat just doesn't write anything.

VBA Code:
Sub Test_GetFinData()
    
    Dim dat, datconv As Variant
    Dim ws As Worksheet
    
    Dim test As Long
    
    Set ws = Worksheets("Sheet1")
    
    dat = '###this is a single array of numeric values grabbed from corporate database (via an api and a separate function not shown)
        
    'test = UBound(dat) - LBound(dat)
    
    With ws
        .Cells(2, 3).Resize(UBound(dat) - LBound(dat) + 1) = dat
    End With

End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Have you tried...
VBA Code:
.Cells(2, 3).Resize(UBound(dat) - LBound(dat) + 1) = Application.Transpose(dat)

This little macro works for me...
VBA Code:
Sub test
Dim abc(2) As Variant

abc(0) = "Bob"
abc(1) = "Tom"
abc(2) = "Jim"
Sheets("Sheet1").Cells(2, 3).Resize(UBound(abc) - LBound(abc) + 1) = Application.Transpose(abc)
End Sub
If I don't use Application.Transpose, then only the first value (Bob) appears in all cells in the range.
 
Upvote 0
Solution
Have you tried...
VBA Code:
.Cells(2, 3).Resize(UBound(dat) - LBound(dat) + 1) = Application.Transpose(dat)

This little macro works for me...
VBA Code:
Sub test
Dim abc(2) As Variant

abc(0) = "Bob"
abc(1) = "Tom"
abc(2) = "Jim"
Sheets("Sheet1").Cells(2, 3).Resize(UBound(abc) - LBound(abc) + 1) = Application.Transpose(abc)
End Sub
If I don't use Application.Transpose, then only the first value (Bob) appears in all cells in the range.
thank you Z51, that did the trick!
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,171
Members
452,615
Latest member
bogeys2birdies

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