+ Reply to Thread
Results 1 to 6 of 6

Macro buttons

  1. #1
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Macro buttons

    Hello,

    I use Excel 2007 and I have created to macros. Those work perfectly well as long as I am in the correct cell.

    I wanted to be able to run the macro whereever I would be in the worksheet and mostly assign my 2 macros to 2 buttons. I Did assign the macro to the button but I still have to be on the correct cell before pushing on my button.

    --> My question is: would it be possible to fix the macro and start it pushing on my button whereever I would be in the sheet?

    Many thanks in advance
    Graig

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Macro buttons

    Show us the code, can't even start without that, and give details of what it needs to do..

  3. #3
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Macro buttons

    Sorry about that. So the first Macro is saving data:
    Sub Macro9()
    '
    ' Macro9 Macro
    '
    ' Keyboard Shortcut: Ctrl+m
    '
    Sheets("Alta activa").Select
    ActiveCell.Rows("1:1").EntireRow.Select
    Selection.Copy
    Sheets("Datos Clientes").Select
    ActiveCell.Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    ActiveCell.Select
    End Sub


    And the second one is clearing data:
    Sub Macro9()
    '
    ' Macro9 Macro
    '
    ' Keyboard Shortcut: Ctrl+m
    '
    Sheets("Alta activa").Select
    ActiveCell.Rows("1:1").EntireRow.Select
    Selection.Copy
    Sheets("Datos Clientes").Select
    ActiveCell.Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    ActiveCell.Select
    End Sub

  4. #4
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Macro buttons

    Sorry the second one is about to clean some data:

    Sub clean()
    '
    ' clean Macro
    '
    ' Keyboard Shortcut: Ctrl+b
    '
    ActiveCell.Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 2).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 2).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, -2).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, -2).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(3, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 3).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(-2, -3).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(-1, 4).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, -4).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 2).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 2).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, -3).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(3, -1).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(3, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 3).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, -3).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 2).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 2).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(1, -1).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(0, -3).Range("A1").Select
    Selection.ClearContents
    ActiveCell.Offset(-29, 0).Range("A1").Select
    End Sub

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro buttons

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Macro buttons

    As well as the code tags, you have not given us any hint of what you want to do as I asked.

    As a starter, don't select. For instance, instead of

    Please Login or Register  to view this content.
    use

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1