+ Reply to Thread
Results 1 to 4 of 4

Creating a worksheet to control which cells a macro sums

Hybrid View

  1. #1
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Creating a worksheet to control which cells a macro sums

    Is there anyway I could create a sheet in my workbook that allows the user to change the range of cells used in a macro, rather than manually editing the code.

    For example, entering something 30:90 in a separate sheet would change the code from 53:86 to the new rows entered.

    HTML Code: 

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Creating a worksheet to control which cells a macro sums

    This is just an example. The code will allows user to select a different range if desired.

    Dim DataRng As Range
    
    If MsgBox("Change Reference?", vbQuestion + vbYesNo, "Change Range") = vbYes Then
    Set DataRng = Application.InputBox("Select Data Range", "Data Range", , , , , , 8)
    MsgBox DataRng.Address
    End If

  3. #3
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Creating a worksheet to control which cells a macro sums

    Sure - put 2 named ranges called RowRef1 and RowRef2 in your spreadsheet where the user will make the row changes. Define 2 new variables in your code: strRowRef1 and strRowRef2. Set the strRowRef variables equal to the the named ranges.
     Dim strRowRef1 As String, strRowRef2 As String
     strRowRef1 = Application.Range("RowRef1").Value
     strRowRef2 = Application.Range("RowRef2").Value
     
     With ws1
            .Range("C53:C86").AutoFilter Field:=1, Criteria1:="=*Revenue 1200*"
        End With
        With ws2
            ActiveSheet.Range("C6").Formula = "=SUBTOTAL(109,Detail!E" & strRowRef1 & ":E" & strRowRef2 & ")"
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  4. #4
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Creating a worksheet to control which cells a macro sums

    JieJenn what should I be typing in to change the range.

    (Ie i want it to use rows 60:70 rather than the ones in the code.)

    I have tried entering C60:70

+ 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