Hi all,
I am trying to transpose multiple data from multiple columns into a single row in a new workbook. My original data simplifies to what is seen below.
Before
Col1 | Col2 | Col3
1 | 2 | 3
1 | 2 | 3
1 | 2 | 3
After
Row1 1 | 1 | 1 | 2 | 2 | 2 | 3 | 3 | 3 So far, I am able to grab Column 1 and do that correctly, however I cannot seem to grab Column 2.
Also, when I try to add in a LastRow lookup, to run the macro again and have it paste to Row 2, it send my Row 1 to Row 43, anyone know what might be causing this?
Here is the code I have so far.
I am trying to transpose multiple data from multiple columns into a single row in a new workbook. My original data simplifies to what is seen below.
Before
Col1 | Col2 | Col3
1 | 2 | 3
1 | 2 | 3
1 | 2 | 3
After
Row1 1 | 1 | 1 | 2 | 2 | 2 | 3 | 3 | 3 So far, I am able to grab Column 1 and do that correctly, however I cannot seem to grab Column 2.
Also, when I try to add in a LastRow lookup, to run the macro again and have it paste to Row 2, it send my Row 1 to Row 43, anyone know what might be causing this?
Here is the code I have so far.
Code:
Sub PartSum()
' Dim workbook import
Dim SummarySheet As Worksheet
Dim FolderPath As String
Dim SelectedFiles() As Variant
Dim NRow As Long
Dim NColumn As Long
Dim Filename As String
Dim NFile As Long
Dim Workbk As Workbook
Dim SourceRange As Range
Dim DestRange As Range
Dim Worksht As Worksheet
Dim C As Range
'Creating and naming worksheets
Set Worksht = ThisWorkbook.Sheets("Part Summary")
'Worksht.Name = Application.InputBox(prompt:="Type Worksheet Name, Include Date of Test", Title:="Worksheet Title", Default:="Enter Here", Type:=2)
'Create a new workbook and set a variable to the first sheet.
Set SummarySheet = Worksht
'Modify this folder path to point to the files to be used.
Dim vFileToOpen As Variant
Dim strCurDir As String
'Keep Original Dir
strCurDir = CurDir
'Open the file dialog box and filter on Excel files, allowing multiple files to be selected.
SelectedFiles = Application.GetOpenFilename(filefilter:="Excel Files (*.xl*), *.xl*", MultiSelect:=True)
'NRow keeps track of where to insert new rows in the destination workbook.
NRow = 1
NColumn = 0
'Loop through the list of returned file names
For NFile = LBound(SelectedFiles) To UBound(SelectedFiles)
'Set FileName to be the current workbook file name to open.
Filename = SelectedFiles(NFile)
'Open the current workbook.
Set Workbk = Workbooks.Open(Filename)
'Set the source range to be D through O.
'Modify this range for your workbooks. It can span multiple rows.
Set SourceRange = Workbk.Worksheets(1).UsedRange.Range("D7:D19")
'Set the destination range to start at column B and be the same size as the source range.
Dim LastRow As Long
LastRow = ThisWorkbook.Sheets("Part Summary").Cells(Rows.Count).End(xlUp).Row + 1
Set DestRange = ThisWorkbook.Sheets("Part Summary").Range("C4" & LastRow)
'Copy over the values from the source to the destination.
For Each C In SourceRange
If Len(C.Value) > 0 Then
C.Copy
DestRange.PasteSpecial Paste:=xlPasteValues, Transpose:=False
Set DestRange = DestRange.Offset(0, 1)
End If
Next C
Application.CutCopyMode = False
'Increase NRow so that we know where to copy data next.
'NRow = NRow + DestRange.Rows.Count + 1
'NColumn = NColumn + DestRange.Columns.Count + 1
'Close the source workbook without saving changes.
Workbk.Close savechanges:=False
Next NFile
' End by resetting to last/original Dir
ChDir strCurDir
End Sub