+ Reply to Thread
Results 1 to 3 of 3

Macro to calculate columns relative to button location

Hybrid View

Fullalove Macro to calculate columns... 09-30-2015, 05:37 PM
Greg M Re: Macro to calculate... 10-01-2015, 06:24 AM
Fullalove Re: Macro to calculate... 10-01-2015, 12:48 PM
  1. #1
    Registered User
    Join Date
    06-11-2012
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Macro to calculate columns relative to button location

    Excel 2013,

    I need a macro that I can assign to a button that will subsequently make columns adjacent to the button calculate when the button is clicked.

    I have a very large document and don't want every equation on the sheet to calculate.

    I will copy and paste this button to several locations so I'd like the the macro to be universal and therefore applicable to any button.

    I've gone in a few circles and figure there's an expert who can cut to the chase.

    Thank you in advance!!!

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Macro to calculate columns relative to button location

    Hi there,

    Take a look at the attached workbook and see if it does what you need.

    The following code is called from each of the various "Calculate" buttons, and recalculates the cells in the column immediately to the left of the "Calculate" button which was clicked:

    
    
    Option Explicit
    
    
    Sub CalculateColumn()
    
        Const iOFFSET   As Integer = -1
    
        Dim rColumn     As Range
        Dim wks         As Worksheet
        Dim shp         As Shape
    
        Set wks = ActiveSheet
    
        On Error Resume Next
            Set shp = wks.Shapes(Application.Caller)
        On Error GoTo 0
    
        If Not shp Is Nothing Then
    
            Set rColumn = shp.TopLeftCell.Offset(0, iOFFSET).EntireColumn
    
            rColumn.Select      '   <<  Just for demonstration - delete from final version
            rColumn.Calculate
    
        End If
    
    End Sub
    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    06-11-2012
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Macro to calculate columns relative to button location

    Thank you for the response! Last night I did a little tinkering (I know nothing John Snow) and I came up with the following that allows me to accomplish the same task you've accomplished, but for a range (i.e. multiple columns).

    Formula: copy to clipboard
    Sub VERSION_REFRESH()
    Dim r As Range
    Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell
    Range(Cells(r.Row, r.Column), Cells(r.Row + 5000, r.Column + 10)).Calculate

    End Sub


    Mind you, it's a little less elegant b/c it requires I define the depth (not just automatically calculating the whole column) but it works.

    Now the problem I'm having with either macro is that it must be run several times to capture iterative calculations. In my columns I have simple calculations and then multiple cells summing the results of those calculations in the same column. The macro works on the first simple calcs, but must be run several more times to make the summation calculations run. Any idea how to address this? Any thoughts on the macro I've inserted? Thank you for your time and expertise!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Data validation list to run macro relative to cell location?
    By yukinosei in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-15-2014, 12:40 PM
  2. [SOLVED] Macro to Calculate Relative Percentage for Each value in Selection
    By lesoies in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-18-2012, 11:29 PM
  3. create macro relative to button location
    By edgonzo101 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2012, 03:17 PM
  4. Relative Macro Button Problems
    By Jackel159 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-12-2009, 08:05 PM
  5. Insert an icon relative to the button location
    By Armidion in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2009, 10:04 AM
  6. insert row macro - relative to button
    By kevlux in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2008, 01:43 PM
  7. Macro Relative reference button greyed out.
    By J Shrimps, Jr. in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2006, 11:40 PM

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