Daisy30825
New Member
- Joined
- Jan 30, 2019
- Messages
- 1
Hi all!!
Very new here. Having a hard time to debug.. I am currently trying to make the macro work as the following:
create new sheets and rename it to cell.Value in range, and if there is a workbook (also named as the sale cell.Value) in the same folder as the macro, copy this sheet into the workbook; if not, create a new workbook, name it the cell.Value and copy the sheet into this new workbook.
i am have trouble with copying the sheet into the existing workbook part: I'm guessing it's the way I'm putting the workbook name??? Please help!!! And Thanks in advance!
Very new here. Having a hard time to debug.. I am currently trying to make the macro work as the following:
create new sheets and rename it to cell.Value in range, and if there is a workbook (also named as the sale cell.Value) in the same folder as the macro, copy this sheet into the workbook; if not, create a new workbook, name it the cell.Value and copy the sheet into this new workbook.
i am have trouble with copying the sheet into the existing workbook part: I'm guessing it's the way I'm putting the workbook name??? Please help!!! And Thanks in advance!
Code:
Dim FilePath As String
FilePath = ""
On Error Resume Next
FilePath = Dir("C:\Users\hsush001\Downloads\test\" & cell.Value & ".xlsx")
On Error GoTo 0
If FilePath = "" Then
ActiveWorkbook.SaveAs Filename:="C:\Users\hsush001\Downloads\test\" & cell.Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Saved = True
ActiveWorkbook.Close SaveChanges:=False
Else
ActiveSheet(cell.Value + " Realized").Copy Before:=Workbooks(cell.Value & ".xlsx").Sheets(1)
ActiveWorkbook.Saved = True
ActiveWorkbook.Close SaveChanges:=False
End If
End With
Next cell
End Sub