Whiskerbizcuit
New Member
- Joined
- Sep 19, 2017
- Messages
- 10
Hey Everyone!
So I'm working on a project to help me out at work. I'm fairly new to VBA so sorry if I sound dumb :P I'm making a macro to copy some raw data from WB1.xlsx to WB2.xlsm The code below is what I'm working with so far, and it works fine, but I need the ranges of the columns to be variable because the data changes from week to week and The columns are never the same length. Any help you can give me would be greatly appreciated. Thanks For Listening!
Sub CopyPasteData()
Dim wb As Workbook
Application.CutCopyMode = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
filePath = "d:\xxxx\xxx\xxxx\xxx.xlsx"
Set wb = Application.Workbooks.Open(filePath)
wb.ActiveSheet.Range("A2:A208").Copy Destination:=ThisWorkbook.Worksheets(2).Columns.Range("A4")
wb.ActiveSheet.Range("B2:B208").Copy Destination:=ThisWorkbook.Worksheets(2).Columns.Range("B4")
wb.ActiveSheet.Range("C2:C208").Copy Destination:=ThisWorkbook.Worksheets(2).Columns.Range("C4")
wb.ActiveSheet.Range("D2:D208").Copy Destination:=ThisWorkbook.Worksheets(2).Columns.Range("E4")
wb.ActiveSheet.Range("E2:E208").Copy Destination:=ThisWorkbook.Worksheets(2).Columns.Range("F4")
wb.Close False
Set wb = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
So I'm working on a project to help me out at work. I'm fairly new to VBA so sorry if I sound dumb :P I'm making a macro to copy some raw data from WB1.xlsx to WB2.xlsm The code below is what I'm working with so far, and it works fine, but I need the ranges of the columns to be variable because the data changes from week to week and The columns are never the same length. Any help you can give me would be greatly appreciated. Thanks For Listening!
Sub CopyPasteData()
Dim wb As Workbook
Application.CutCopyMode = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
filePath = "d:\xxxx\xxx\xxxx\xxx.xlsx"
Set wb = Application.Workbooks.Open(filePath)
wb.ActiveSheet.Range("A2:A208").Copy Destination:=ThisWorkbook.Worksheets(2).Columns.Range("A4")
wb.ActiveSheet.Range("B2:B208").Copy Destination:=ThisWorkbook.Worksheets(2).Columns.Range("B4")
wb.ActiveSheet.Range("C2:C208").Copy Destination:=ThisWorkbook.Worksheets(2).Columns.Range("C4")
wb.ActiveSheet.Range("D2:D208").Copy Destination:=ThisWorkbook.Worksheets(2).Columns.Range("E4")
wb.ActiveSheet.Range("E2:E208").Copy Destination:=ThisWorkbook.Worksheets(2).Columns.Range("F4")
wb.Close False
Set wb = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub