Exceliscool123456789
New Member
- Joined
- Sep 5, 2023
- Messages
- 30
- Office Version
- 365
- Platform
- Windows
Hi,
I'm having trouble running a code that will extract certain values (10285, 10160 & 13456) from the data source sheet and paste it into different tabs on a second workbook (wb.2) in the first available row (rolling tally). This is my code below, any assistance would be greatly appreciated.
Code objective:
1). Open data source sheet and label it as wb.1
2). Within the data source sheet, filter on column D for values - 10285, 10160 & 13456
3). Activate the second workbook in a specific folder - J:\DEPT-FINANCE\MONTH END - F2023STUB
4). The second workbook will be titled "Bank Transactions - MMM YYYY" in xlsm format
6a). Each row of data pertaining to that specific value in workbook 1 (10285, 10160 & 13456) should be pasted into their respective tabs underneath the first available row in the second workbook.
6b). Tabs: GL10285
GL10160
GL13456
Dim file1 As String
Dim file2 As String
Dim wb As Workbook
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim lr1 As Long
Dim lr2 As Long
' Loop through all open workbooks to identify Datadump file
For Each wb In Application.Workbooks
If Left(wb.Name, 8) = "FIN-BANK" And Right(wb.Name, 3) = "csv" Then
Set wb1 = wb
End If
Next wb
For Each a In Array("10285", "10160", "13456")
s = "GL " & a
With WsSrc.Range("D1").CurrentRegion
.AutoFilter 6, a
If .SpecialCells(xlCellTypeVisible).Address <> .Rows(1).Address Then
.Offset(1).Resize(.Rows.Count - 1).Copy _
wb2.Worksheets(s).Cells(Rows.Count, 1).End(xlUp).Offset(1)
End If
.AutoFilter
End With
Next a
Application.ScreenUpdating = True
' Browse to open Bank Transactions File
file2 = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsm*),*.xlsm*", Title:="Bank Transactions")
Set wb2 = Workbooks.Open(file2)
wb1.Activate
Range("A1:N" & lr1).Copy
wb2.Activate
Sheets("GL10266").Activate
Range("A" & lr2 + 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
' Close original CSV file
wb1.Close
' Save update Excel file
wb2.Save
End Sub
I'm having trouble running a code that will extract certain values (10285, 10160 & 13456) from the data source sheet and paste it into different tabs on a second workbook (wb.2) in the first available row (rolling tally). This is my code below, any assistance would be greatly appreciated.
Code objective:
1). Open data source sheet and label it as wb.1
2). Within the data source sheet, filter on column D for values - 10285, 10160 & 13456
3). Activate the second workbook in a specific folder - J:\DEPT-FINANCE\MONTH END - F2023STUB
4). The second workbook will be titled "Bank Transactions - MMM YYYY" in xlsm format
6a). Each row of data pertaining to that specific value in workbook 1 (10285, 10160 & 13456) should be pasted into their respective tabs underneath the first available row in the second workbook.
6b). Tabs: GL10285
GL10160
GL13456
Dim file1 As String
Dim file2 As String
Dim wb As Workbook
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim lr1 As Long
Dim lr2 As Long
' Loop through all open workbooks to identify Datadump file
For Each wb In Application.Workbooks
If Left(wb.Name, 8) = "FIN-BANK" And Right(wb.Name, 3) = "csv" Then
Set wb1 = wb
End If
Next wb
For Each a In Array("10285", "10160", "13456")
s = "GL " & a
With WsSrc.Range("D1").CurrentRegion
.AutoFilter 6, a
If .SpecialCells(xlCellTypeVisible).Address <> .Rows(1).Address Then
.Offset(1).Resize(.Rows.Count - 1).Copy _
wb2.Worksheets(s).Cells(Rows.Count, 1).End(xlUp).Offset(1)
End If
.AutoFilter
End With
Next a
Application.ScreenUpdating = True
' Browse to open Bank Transactions File
file2 = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsm*),*.xlsm*", Title:="Bank Transactions")
Set wb2 = Workbooks.Open(file2)
wb1.Activate
Range("A1:N" & lr1).Copy
wb2.Activate
Sheets("GL10266").Activate
Range("A" & lr2 + 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
' Close original CSV file
wb1.Close
' Save update Excel file
wb2.Save
End Sub