Can someone tell me what this line of code is doing??? Thanks

rob_sheeds

Board Regular
Joined
Dec 9, 2010
Messages
57
This line lies within this sub below....what is it doing as it doesnt work properly....
Sheets("Sheet" & i).Cells.Value = Sheets("Sheet" & i).Cells.Value

Comes from Sub:
Dim i As Long
Workbooks.Open Filename:= _
"C:\Users\rsheedy\Desktop\Daily Sales\Daily Sales Report NEW Open Sales Orders - Copy.xlsm"
ActiveWorkbook.SaveAs Filename:="R:\Reports\Archive\Daily Sales Reports\May 2011\DSR_" & Format(Date, "DDMMYYYY") & ".xlsm", _
FileFormat:=52, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

With ActiveWorkbook
For i = 1 To 6

Sheets("Sheet" & i).Cells.Value = Sheets("Sheet" & i).Cells.Value

Next i

End With
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
That line is attempting to convert the entire sheet to values, but it can be problematic because it's covering such a large range.

Try:

Code:
        With Sheets("Sheet" & i).Cells
            .Copy
            .PasteSpecial Paste:=xlPasteValues
        End With

HTH,
 
Upvote 0
Thanks Smitty,
Can you suggest some better code? Also is it irrelevant if the sheets are called something different?
Cheers
 
Upvote 0
Can you suggest some better code?

Not really, if you're trying to get rid of formulas you need to value them out somehow.

Also is it irrelevant if the sheets are called something different?

Nope, your code doesn't care what the sheets are named since it's iterating through them based on #1 through #6. It could be an issue if you have more/less than 6 sheets, or if there are some you don't want to alter.

I usually use For i = 1 to Sheets.Count which means you don't have to take account of how many sheets there will be, as VBA will figure it out.
 
Upvote 0
Hmm still wont quite work. Same error.
Note 3 of my sheets are hidden.
Can you suggest something to only copy/paste values A1:T500 for
Sheet = "Daily Sales Report", "Open Orders", 'SOGS"
Again I appreciate you time.

Code now looks like this.
Sub robsheeds()
Dim i As Long
Workbooks.Open Filename:= _
"C:\Users\rsheedy\Desktop\Daily Sales\Daily Sales Report NEW Open Sales Orders - Copy.xlsm"
ActiveWorkbook.SaveAs Filename:="R:\Reports\Archive\Daily Sales Reports\May 2011\DSR_" & Format(Date, "DDMMYYYY") & ".xlsm", _
FileFormat:=52, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

With ActiveWorkbook
For i = 1 To Sheets.Count

With Sheets("Sheet" & i).Cells
.Copy
.PasteSpecial Paste:=xlPasteValues
End With

Next i

End With
Mail_workbook_Outlook_1
End Sub

Thanks
 
Upvote 0
Can you suggest something to only copy/paste values A1:T500 for
Sheet = "Daily Sales Report", "Open Orders", 'SOGS"

The best way to get that code would be to group the sheets and record a macro. If they're hidden then for grouping purposes, just unhide them, do your thing and rehide.

Post back the code you get and someone can clean it up for you.
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,818
Members
452,946
Latest member
JoseDavid

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