Almost there...Just need your help on some code or function

Hlatigo

Well-known Member
Joined
Jun 3, 2002
Messages
677
Hello everyone,

I found some code that takes each sheet in the workbook and saves it into another workbook but the problem is if there are three sheets than that means three seperate workbooks.

I want all three worksheets in the same wrkbook. I cant just do save or save as because the master file will be saving the code as well and that would cause some problems.

Does anyone know how to help?

Thanks so much in advance!!

Latigo :cool:



Sub Copy_All_Sheets_To_New_Workbook()
Dim WbMain As Workbook
Dim Wb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String


Application.ScreenUpdating = False
Application.EnableEvents = False

DateString = Format(Now, "mm-dd-yyyy")
Set WbMain = ThisWorkbook
FolderName = WbMain.Path & "\" & Left(WbMain.Name, Len(WbMain.Name) - 4) & " " & DateString
MkDir FolderName


For Each sh In WbMain.Worksheets
If sh.Visible = -1 Then
sh.Copy
Set Wb = ActiveWorkbook


' Make values from the formulas

' With Wb.Sheets(1).UsedRange
' .Value = .Value
' End With


'Wb.SaveAs FolderName _
'& "\" & Wb.Sheets(1).Name & ".xls"
'Wb.Close False
End If
Next sh


MsgBox "Look in " & FolderName & " for the files"
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hlatigo,

Sometimes we're surprised by the simplicity of code. In the past I've spent hours to find a solution to this and just now this simple oneliner came into my mind:

Sheets.Copy

does this work for you too ?

kind regards,
Erik
 
Upvote 0
WOW

OMG!!!

I thought to myself, "latigo, there has to be a simple two or three word function that would do it all"

It worked like a charm!!! thanks so very much for your help, I will be able to finish this up way b4 schedule.

Thanks a million :p

Latigo
 
Upvote 0

Forum statistics

Threads
1,221,639
Messages
6,160,998
Members
451,682
Latest member
ogoreo

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