Transpose row to column VBA

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hi i am trying to add code to transpose the row to a column where it pastes in the column M (13) until the last column used in that row 1 and put the values down in cell A2 down
I am having trouble getting the vba to go with it

VBA Code:
  Dim FNames As Variant
  Dim Cnt As Long
  Dim Wbk As Workbook
  Dim MstWbk As Workbook
  Dim Ws As Worksheet
  'Dim wb As Workbook: Set wb = ThisWorkbook
  Dim rng As Range
  Dim I As Long
  
  Set MstWbk = ThisWorkbook
     
  FNames = Application.GetOpenFilename(FileFilter:="Excel files (*.xls*), *.xls*", MultiSelect:=False)
  If FNames = False Then Exit Sub
  Set Wbk = Workbooks.Open(FNames)
  Wbk.Worksheets("Calculation").Range("M6:BW6").Copy
  shtCompare.Cells(1, 13).PasteSpecial xlPasteValues
  Wbk.Close False
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I updated the macro.
Notice how I made the declaration of the variables.
You only have to adjust the name of the sheet where you are going to paste the data.


VBA Code:
Sub transposeColumn()
  Dim FNames As Variant
  Dim Wbk As Workbook
  Dim shtCompare As Worksheet
 
  Set shtCompare = ThisWorkbook.Sheets("Sh1") 'Fit the name of the sheet where you are going to paste
    
  FNames = Application.GetOpenFilename(FileFilter:="Excel files (*.xls*), *.xls*", MultiSelect:=False)
  If FNames = False Then Exit Sub
 
  Set Wbk = Workbooks.Open(FNames)
  With Wbk.Worksheets("Calculation")
    .Range("M6", .Cells(6, .Cells(6, Columns.Count).End(1).Column)).Copy
  End With
  shtCompare.Range("A2").PasteSpecial xlPasteValues, Transpose:=True
  Wbk.Close False
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0

Forum statistics

Threads
1,215,357
Messages
6,124,483
Members
449,165
Latest member
ChipDude83

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