Copying sheets to existing workbook, workbook name is cell.value

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!

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
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top