Remove Paste Special from Macro

rusted314

Board Regular
Joined
Jan 12, 2010
Messages
74
Hi, I have the macro below that will take all of the Workbooks in a folder and copy the worksheet of my choice into a master document. The macro is setup to paste values and I need to have have the formulas included when the worksheets are copied. I tried removing the line of code " Sheets(c).Range("A1").PasteSpecial" but that didnt work. Can someone please modify this for me so the formulas are included when I run the macro?
Thanks



Sub Daily_Staffing_Rollup_PV()
Dim MyInput As String
MyInput = InputBox("What Day of The Week Do You Need?", _
"MyInputTitle", "Enter day here ie. Monday")
If MyInput = "Enter your input text HERE" Or _
MyInput = "" Then
Exit Sub
End If



Dim z As Long, e As Long
Dim f As String, b As String, c As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks("master.xls").Sheets("Sheet1").Cells(1, 1) = "=cell(""filename"")"
Workbooks("master.xls").Sheets("Sheet1").Cells(1, 2) = "=left(A1,find(""["",A1)-1)"
Workbooks("master.xls").Sheets("Sheet1").Cells(2, 1).Select
f = Dir(Workbooks("master.xls").Sheets("Sheet1").Cells(1, 2) & "*.xls")
Do While Len(f) > 0
ActiveCell.Formula = f
ActiveCell.Offset(1, 0).Select
f = Dir()
Loop
z = Workbooks("master.xls").Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For e = 2 To z
b = Workbooks("master.xls").Sheets("Sheet1").Cells(e, 1)
If b <> ActiveWorkbook.Name Then
c = Mid(Left(b, Len(b) - 4), 1, 30)
Workbooks.Open Filename:=Workbooks("master.xls").Sheets("Sheet1").Cells(1, 2) & Workbooks("master.xls").Sheets("Sheet1").Cells(e, 1)
Worksheets(MyInput).UsedRange.Copy 'Change sheetname if it is incorrect
ActiveWorkbook.Close False
Sheets.Add.Name = c
Sheets(c).Range("A1").PasteSpecial
End If
Next e
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Worksheets.Add().Name = "Summary"
MsgBox "collating is complete and summary sheet added."
' Local Variables
Dim wks As Worksheet
Dim rngLinkCell As Range
Dim strSubAddress As String, strDisplayText As String
' Step 1 : Loop through all worksheets
' 1a : Clear all current hyperlinks
Worksheets("Summary").Range("A:A").ClearContents
' 1b : Create Linked index list
For Each wks In ActiveWorkbook.Worksheets
Set rngLinkCell = Worksheets("Summary").Range("A65536").End(xlUp)
If rngLinkCell <> "" Then Set rngLinkCell = rngLinkCell.Offset(1, 0)
strSubAddress = "'" & wks.Name & "'!A1"
strDisplayText = wks.Name
Worksheets("Summary").Hyperlinks.Add Anchor:=rngLinkCell, Address:="", SubAddress:=strSubAddress, TextToDisplay:=strDisplayText
Next wks

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Code:
Sub Daily_Staffing_Rollup_PV()
Dim MyInput As String
MyInput = InputBox("What Day of The Week Do You Need?", _
"MyInputTitle", "Enter day here ie. Monday")
If MyInput = "Enter your input text HERE" Or _
MyInput = "" Then
Exit Sub
End If
 
 
 
Dim z As Long, e As Long
Dim f As String, b As String, c As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks("master.xls").Sheets("Sheet1").Cells(1, 1) = "=cell(""filename"")"
Workbooks("master.xls").Sheets("Sheet1").Cells(1, 2) = "=left(A1,find(""["",A1)-1)"
Workbooks("master.xls").Sheets("Sheet1").Cells(2, 1).Select
f = Dir(Workbooks("master.xls").Sheets("Sheet1").Cells(1, 2) & "*.xls")
Do While Len(f) > 0
ActiveCell.Formula = f
ActiveCell.Offset(1, 0).Select
f = Dir()
Loop
z = Workbooks("master.xls").Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For e = 2 To z
b = Workbooks("master.xls").Sheets("Sheet1").Cells(e, 1)
If b <> ActiveWorkbook.Name Then
c = Mid(Left(b, Len(b) - 4), 1, 30)
Workbooks.Open Filename:=Workbooks("master.xls").Sheets("Sheet1").Cells(1, 2) & Workbooks("master.xls").Sheets("Sheet1").Cells(e, 1)
Worksheets(MyInput).UsedRange.Copy 'Change sheetname if it is incorrect
ActiveWorkbook.Close False
Sheets.Add.Name = c
Sheets(c).Range("A1").PasteSpecial Paste:=xlPasteAll
End If
Next e
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Worksheets.Add().Name = "Summary"
MsgBox "collating is complete and summary sheet added."
' Local Variables
Dim wks As Worksheet
Dim rngLinkCell As Range
Dim strSubAddress As String, strDisplayText As String
' Step 1 : Loop through all worksheets
' 1a : Clear all current hyperlinks
Worksheets("Summary").Range("A:A").ClearContents
' 1b : Create Linked index list
For Each wks In ActiveWorkbook.Worksheets
Set rngLinkCell = Worksheets("Summary").Range("A65536").End(xlUp)
If rngLinkCell <> "" Then Set rngLinkCell = rngLinkCell.Offset(1, 0)
strSubAddress = "'" & wks.Name & "'!A1"
strDisplayText = wks.Name
Worksheets("Summary").Hyperlinks.Add Anchor:=rngLinkCell, Address:="", SubAddress:=strSubAddress, TextToDisplay:=strDisplayText
Next wks
 
End Sub
 
Upvote 0
Thank you for the quick reply. Unfortunately it is still copying values only. Does anyone know how to copy the full worksheet in its original form with all formulas?
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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