Selecting Specialcells in all sheets

davper

New Member
Joined
Jun 30, 2010
Messages
11
I am having trouble looping through the sheets in my workbook and selecting SpecialCells.

When I run this code, it only processes the activesheet.
Code:
Sub Testz()
Dim Page As Worksheet
    For Each Page In ActiveWorkbook.Worksheets
        Selection.SpecialCells(xlCellTypeFormulas, 23).Select
    Next
End Sub

My first try was
Code:
Page.SpecialCells(xlCellTypeFormulas, 23).Select
But that just gave me a 'Selection method failure.

I know it is looping through all sheets because I put in a debug.print to give me each sheet name.

I have tried using xlNumbers instead of 23. I have left it blank.

This is a very simple code for demonstration. My actual code is going to process each cell individually depending on further criteria.

Please and Thank You
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
This is the other code that I tried that gives me a 'Selection Method' error:
Code:
Sub Testz()
Dim Page As Worksheet
    For Each Page In ActiveWorkbook.Worksheets
        'Selection.SpecialCells(xlCellTypeFormulas, 23).Select
        Page.UsedRange.SpecialCells(xlCellTypeFormulas).Select
    Next
End Sub
 
Upvote 0
if you are hell bent on selecting the cell (which 99% of the time is superfluous) then try adding page.select before the selection line.

-Justin
 
Upvote 0
Try

Code:
Sub Testz()
Dim Page As Worksheet
    For Each Page In ActiveWorkbook.Worksheets
        Page.Select
        SpecialCells(xlCellTypeFormulas, 23).Select
    Next
End Sub
 
Upvote 0
I am not hell bent on selecting. By using select while testing, I can get an immediate visual clue that it worked.

page.select worked for me. Thank you

here is my actual code for the curious
Code:
For Each Page In ActiveWorkbook.Worksheets
    Page.Select
    Set rngRange = Page.UsedRange.SpecialCells(xlCellTypeFormulas)
    For Each rngCell In rngRange
        If InStr(rngCell.Formula, "AMOUNT") Then
            rngCell.Formula = rngCell.Value
        End If
        If InStr(rngCell.Formula, "[") Then
            rngCell.Formula = rngCell.Value
        End If
    Next
Next
 
Upvote 0
I don't think you'll need the page.select on that. Did you try that particular code w/o the select?
 
Upvote 0
That will work without Page.Select

I would like to think that I hit the reply button before you, but since my reply was longer, it took me longer to write. However, that is probably not the case.
 
Upvote 0
You surprise me. What about

Code:
For Each Page In ActiveWorkbook.Worksheets
    With Page
        Set rngRange = .UsedRange.SpecialCells(xlCellTypeFormulas)
        For Each rngCell In rngRange
            If InStr(rngCell.Formula, "AMOUNT") Then
                rngCell.Formula = rngCell.Value
            End If
            If InStr(rngCell.Formula, "[") Then
                rngCell.Formula = rngCell.Value
            End If
        Next
    End With
Next
 
Upvote 0

Forum statistics

Threads
1,215,394
Messages
6,124,683
Members
449,180
Latest member
kfhw720

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