jmac001
asked on
VBA Paste Column in Non-Sequential Order
Hi Experts,
Looking for a little assistance, I need to copy over some columns the range is A7:C70, F7:I70,K7:K70,D7:D70,L7:L7 0, DE7:EZ70 in this order. However when I run the vba it copies the data over in sequential order. How would I update the vba to place in the order specified?
Here is the macro
Looking for a little assistance, I need to copy over some columns the range is A7:C70, F7:I70,K7:K70,D7:D70,L7:L7
Here is the macro
Sub BCopySummaryData()
Dim wb As Workbook
Dim fso As FileSystemObject
Dim myFolder As Folder
Dim myFile As File
Dim newestFile As File
Dim ws As Worksheet
Set fso = New FileSystemObject
'Delete Current Data below header
With Sheets("BSum")
Rows("7:65536").Select
Selection.Delete
Range("A7").Select
End With
Application.AskToUpdateLinks = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'--------------------------------------------------------------------------------
'For test purposes, I am using the "My Documents" folder... this needs to change
' To use whatever folder you need
'--------------------------------------------------------------------------------
Set myFolder = fso.GetFolder("\\SSFilePrint\GROUPSHARE\Store Planning\LSP Shared")
For Each myFile In myFolder.Files
Select Case UCase(fso.GetExtensionName(myFile.Path))
Case "XLS", "XLSM", "XLSB", "XLSX":
If newestFile Is Nothing Then
Set newestFile = myFile
ElseIf myFile.DateLastModified > newestFile.DateLastModified Then
Set newestFile = myFile
End If
End Select
Next
'--------------------------------------------------------------------------------
'At this point... "newestFile" is a File object that is the newest Excel File in your folder
' The following code will open it, and now you have to copy from whatever range you need data from
'--------------------------------------------------------------------------------
If Not newestFile Is Nothing Then
Application.Workbooks.Open newestFile.Path
Set wb = Application.Workbooks(newestFile.Name)
'or if you now the name of the sheet it could be something like : Set ws = wb.Sheets("Sheet1")
Set ws = wb.Sheets("Summary")
Set lastSourceCell = LastCell(ws)
If lastSourceCell Is Nothing Then
MsgBox "Nothing to copy - stopping"
wb.Close
Exit Sub
End If
Set lastDestCell = LastCell(ThisWorkbook.Sheets("BSum"))
If lastDestCell Is Nothing Then
destinationRow = 1
Else
destinationRow = lastDestCell.Row + 1
End If
ws.Range("A7:C70, F7:I70,K7:K70,D7:D70,L7:L70, DE7:EZ70").Copy
ThisWorkbook.Sheets("BSum").Range("A" & destinationRow).PasteSpecial xlPasteValues
ThisWorkbook.Sheets("BSum").Range("A" & destinationRow).PasteSpecial xlPasteFormats
destinationRow = destinationRow + 1
Application.ScreenUpdating = True
Application.DisplayAlerts = False
wb.Close
MsgBox "Copy Complete"
End If
'Add date ran
Sheets("BSum").Range("F1").Value = Date
Application.Calculation = xlCalculationAutomatic
MsgBox "All Updates Complete"
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER