Macro error help

anilag1bowl

New Member
Joined
Sep 12, 2014
Messages
1
Hey guys, I'm a savvy excel user, but not huge in the programming/macro side. I keep getting this error on a simple button to turn formulas into values, and save the workbook as a static.

Error: Run-time error '1004': Select method of Button class failed


Dropping the code in and the error highlighted by VisualBasic, can I please get some help how to fix? The Macro does not work.

image003_1.png


image.png




Thanks!

Anilag
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
.
.

Not sure why that line isn't working for you; it appears to work ok on my PC.


Try something like the following instead:

Code:
Sub AddButton()

    Dim Btn As Button
    Dim Rng As Range
    
    If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
    
    Select Case TypeName(Selection)
        Case Is = "Range": Set Rng = Selection.Item(1).Resize(3, 3)
        Case Else: Set Rng = ActiveSheet.Range("B2:D4")
    End Select
    
    With Rng
        Set Btn = ActiveSheet.Buttons.Add(.Left, .Top, .Width, .Height)
    End With
    
    With Btn
        .Caption = "Paste Values and Save"
        .OnAction = "PasteValuesAndSave"
    End With

End Sub


Sub PasteValuesAndSave()

    Dim Sel As Object
    Dim FRang As Range
    Dim FArea As Range
    
    If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
    
    On Error Resume Next
    Set FRang = ActiveSheet.Cells.SpecialCells( _
        xlCellTypeFormulas, _
        xlErrors + xlLogical + xlNumbers + xlTextValues)
    On Error GoTo 0
    
    If Not FRang Is Nothing Then
        Set Sel = Selection
        Application.ScreenUpdating = False
    
        For Each FArea In FRang.Areas
            With FArea
                .Copy
                .PasteSpecial Paste:=xlPasteValues
            End With
        Next FArea
        
        Sel.Select
        With Application
            .CutCopyMode = False
            .ScreenUpdating = True
        End With
    End If
    
    ActiveWorkbook.Save

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,896
Messages
6,122,132
Members
449,066
Latest member
Andyg666

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