UBound Array with Transpose

Glasgowsmile

Active Member
Joined
Apr 14, 2018
Messages
280
Office Version
  1. 365
Platform
  1. Windows
Good day,

I have the following code and I need to transpose one of the returns but I'm unsure how to easily go about it.

VBA Code:
Dim wkbCrntWorkBook As Workbook
   Dim wkbSourceBook As Workbook
  
   Dim sh As Worksheet, ws As Worksheet
   Dim rg1 As Variant, rg2 As Variant, rg3 As Variant
   Dim r1 As Long, c1 As Long
   Dim r2 As Long, c2 As Long
   Dim r3 As Long, c3 As Long
  
   Set wkbCrntWorkBook = ActiveWorkbook
   Set sh = ActiveSheet
  
   If .SelectedItems.Count > 0 Then
         Workbooks.Open .SelectedItems(1)
         Set wkbSourceBook = ActiveWorkbook
         Set ws = wkbSourceBook.Sheets(1)
        
         With ws
            rg1 = .Range("S4:S5").Value
            rg2 = .Range("P9:Q33").Value
            rg3 = .Range("J123:J147").Value
        
            r1 = UBound(rg1): c1 = UBound(rg1, 2)
            r2 = UBound(rg2): c2 = UBound(rg2, 2)
            r3 = UBound(rg3): c3 = UBound(rg3, 2)
         End With
        
         With sh
        
         .Range("A2").Resize(r1, c1).Value = rg1 <-- I need this transposed
         .Range("A5").Resize(r2, c2).Value = rg2
         .Range("C5").Resize(r3, c3).Value = rg3
        
         End With
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
How about
VBA Code:
.Range("A2").Resize(c1, r1).Value = Application.Transpose(rg1)
 
Upvote 0
Solution
If it's pulling the wrong cell that has nothing to do with changing that one line of code.
Also it works for me the data from S4:S5 goes into A2:B2
 
Upvote 0
If it's pulling the wrong cell that has nothing to do with changing that one line of code.
Also it works for me the data from S4:S5 goes into A2:B2

I found that it pulls the right data, just wrong formatting on the cell but it doesn't transpose. It should be going into A2:B2 but it goes into A2 and A3.
 
Upvote 0
That's exactly what the code I posted does, did you copy paste the code, or change what you already had?

Weird. I typed it in and it didn't work, I copied it over and it works? I don't understand that but at least it works. Thanks!
 
Upvote 0
Did you change the order of the arguments in the Resize?
 
Upvote 0
Did you change the order of the arguments in the Resize?

No, I typed exactly as I saw it and re-checked it multiple times against what you suggested but it looked exactly the same. Even when I copied/pasted your code, nothing changed from what I saw but I obviously must have missed something.
 
Upvote 0
Ok, glad it's working & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
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