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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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