Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modify macro to run on active worksheet only 2

Status
Not open for further replies.

garvock

Technical User
Jan 22, 2004
16
GB
I use a macro to replace formulas with values, I need to modify it to run on the active worksheet only.Please help, I do not understand visual basic. Here is the code:
Sub FormulasToValues()
'
' Replace all formulas with values
'

WCount = Worksheets.Count
For i = 1 To WCount
If Worksheets(WCount - i + 1).Visible Then
Worksheets(WCount - i + 1).Select
RCount = ActiveCell.SpecialCells(xlLastCell).Row
CCount = ActiveCell.SpecialCells(xlLastCell).Column
For j = 1 To RCount
For k = 1 To CCount
Worksheets(WCount - i + 1).Cells(j, k) = Worksheets(WCount - i + 1).Cells(j, k).Value
Next k
Next j
End If
Next i

End Sub

Thanks in anticipation!!
 
Sub FormulasToValues()
'
' Replace all formulas with values
'


RCount = ActiveCell.SpecialCells(xlLastCell).Row
CCount = ActiveCell.SpecialCells(xlLastCell).Column
For j = 1 To RCount
For k = 1 To CCount
Worksheets(WCount - i + 1).Cells(j, k) = Worksheets(WCount - i + 1).Cells(j, k).Value
Next k
Next j


End Sub
 
Thanks Mrmovie for that info. It works well but only on the first worksheet not on the active worksheet. Any other suggestions?
Thanks again!
 


Hi,

Simplify!
Code:
Sub FormulasToValues()
    Dim ws As Worksheet, r As Range
    For Each ws In Worksheets
        With ws
            If .Visible Then
                For Each r In .UsedRange
                    With r
                        .Value = .Value
                    End With
                Next
            End If
        End With
    Next
End Sub

Skip,

[glasses] [red]Be Advised![/red] For those this winter, caught in Arctic-like calamity, be consoled...
Many are cold, but few are frozen![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top