Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default SpecialCells(Formula) -- Value

I need to copy a worksheet, and convert all formulas in the copy to values.
I tried the following two methods without success. How can I do this?

Thanks in advance.

Sub CopyWSValues(ws As Worksheet)

ws.Copy After:=Sheets(ThisWorkbook.Sheets.Count)
Cells.SpecialCells(xlCellTypeFormulas).Value =
Cells.SpecialCells(xlCellTypeFormulas).Value

Exit Sub ' other method below
ws.Copy After:=Sheets(ThisWorkbook.Sheets.Count)
ActiveSheet.Range("Print_Area").SpecialCells(xlCel lTypeFormulas) =
_ ActiveSheet.Range("Print_Area").SpecialCells(xlCel lTypeFormulas).Value

End Sub

Darren
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default SpecialCells(Formula) -- Value

SpecialCells(xlCellTypeFormulas) is likely to give you a multiple area
range. You could do a loop:

Dim rArea As Range
For Each rArea In .SpecialCells(xlCellTypeFormulas).Areas
rArea.Value = rArea.Value
Next

or simply

ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value

since it doesn't change anything for cells that don't contain formulas.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Darren Hill" wrote in message
...
I need to copy a worksheet, and convert all formulas in the copy to values.
I tried the following two methods without success. How can I do this?

Thanks in advance.

Sub CopyWSValues(ws As Worksheet)

ws.Copy After:=Sheets(ThisWorkbook.Sheets.Count)
Cells.SpecialCells(xlCellTypeFormulas).Value =
Cells.SpecialCells(xlCellTypeFormulas).Value

Exit Sub ' other method below
ws.Copy After:=Sheets(ThisWorkbook.Sheets.Count)
ActiveSheet.Range("Print_Area").SpecialCells(xlCel lTypeFormulas) = _
ActiveSheet.Range("Print_Area").SpecialCells(xlCel lTypeFormulas).Value

End Sub

Darren



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default SpecialCells(Formula) -- Value

If you're converting the formulas to values, you could drop the .specialcells()
stuff and just use the entire range.

with activesheet.usedrange 'did you really want to specify just the print_area?
.value = .value
end with

or
with activesheet.usedrange
.copy
.pastespecial paste:=xlpastevalues
end with

=====
If you wanted to use the .specialcells, then you'll have to do each area
separately:

dim myArea as range
for each myArea in activesheet.cells.specialcells(xlcelltypeformulas) .areas
with myarea
.value = .value
end with
'or
with myarea
.copy
.pastespecial paste:=xlpastevalues
end with
next myarea




Darren Hill wrote:

I need to copy a worksheet, and convert all formulas in the copy to values.
I tried the following two methods without success. How can I do this?

Thanks in advance.

Sub CopyWSValues(ws As Worksheet)

ws.Copy After:=Sheets(ThisWorkbook.Sheets.Count)
Cells.SpecialCells(xlCellTypeFormulas).Value =
Cells.SpecialCells(xlCellTypeFormulas).Value

Exit Sub ' other method below
ws.Copy After:=Sheets(ThisWorkbook.Sheets.Count)
ActiveSheet.Range("Print_Area").SpecialCells(xlCel lTypeFormulas) =
_ ActiveSheet.Range("Print_Area").SpecialCells(xlCel lTypeFormulas).Value

End Sub

Darren


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default SpecialCells(Formula) -- Value

Thanks, Jon and Dave. Lightning fast service!

Dave, you asked: "did you really want to specify just the print_area?"
No, but I was trying to limit the area being operated on.
I tried activesheet.cells.value = activesheet.cells.value and got "Out
of Memory".
I had forgotten about UsedRange! Thanks for reminding me.

Darren

Dave Peterson wrote:
If you're converting the formulas to values, you could drop the .specialcells()
stuff and just use the entire range.

with activesheet.usedrange 'did you really want to specify just the print_area?
.value = .value
end with

or
with activesheet.usedrange
.copy
.pastespecial paste:=xlpastevalues
end with

=====
If you wanted to use the .specialcells, then you'll have to do each area
separately:

dim myArea as range
for each myArea in activesheet.cells.specialcells(xlcelltypeformulas) .areas
with myarea
.value = .value
end with
'or
with myarea
.copy
.pastespecial paste:=xlpastevalues
end with
next myarea




Darren Hill wrote:
I need to copy a worksheet, and convert all formulas in the copy to values.
I tried the following two methods without success. How can I do this?

Thanks in advance.

Sub CopyWSValues(ws As Worksheet)

ws.Copy After:=Sheets(ThisWorkbook.Sheets.Count)
Cells.SpecialCells(xlCellTypeFormulas).Value =
Cells.SpecialCells(xlCellTypeFormulas).Value

Exit Sub ' other method below
ws.Copy After:=Sheets(ThisWorkbook.Sheets.Count)
ActiveSheet.Range("Print_Area").SpecialCells(xlCel lTypeFormulas) =
_ ActiveSheet.Range("Print_Area").SpecialCells(xlCel lTypeFormulas).Value

End Sub

Darren


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How are these uses of SpecialCells different? M. Authement Excel Programming 0 May 28th 07 08:16 PM
SpecialCells help Graham Y Excel Programming 2 October 11th 06 05:16 PM
SpecialCells mike Excel Programming 4 June 8th 06 01:50 AM
SpecialCells Peter Excel Programming 3 April 12th 06 02:03 PM
Specialcells Bruno Uato Charts and Charting in Excel 0 October 7th 05 07:42 PM


All times are GMT +1. The time now is 09:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"