+ Reply to Thread
Results 1 to 10 of 10

Adding various cells on a click??

Hybrid View

tholiver Adding various cells on a... 08-23-2012, 11:48 AM
patel45 Re: Adding various cells on a... 08-23-2012, 12:10 PM
tholiver Re: Adding various cells on a... 08-24-2012, 11:02 AM
patel45 Re: Adding various cells on a... 08-25-2012, 05:09 AM
tholiver Re: Adding various cells on a... 08-25-2012, 10:18 AM
patel45 Re: Adding various cells on a... 08-25-2012, 11:57 AM
tholiver Re: Adding various cells on a... 08-25-2012, 12:35 PM
patel45 Re: Adding various cells on a... 08-25-2012, 02:45 PM
tholiver Re: Adding various cells on a... 08-25-2012, 03:01 PM
tholiver Re: Adding various cells on a... 09-14-2012, 01:44 PM
  1. #1
    Registered User
    Join Date
    08-17-2012
    Location
    Coventry, UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Adding various cells on a click??

    Hi All,

    I'm having a `vision` (sounds ambitious ) to use a spreadsheet as a quotation tool. What I mean is, imagine a cost of a generic product to which you'd like to add certain options but not all. Then, some sort of trigger is needed to add all highlighted options on a 1 click.

    For example, I'd like to highlight 3 out of 6 options and, say, change the background color of these cells to blue, which would automatically trigger a sum function to be placed in a `total` cell. Is this possible? Could anyone help me and work out some magic?

    Many thanks in anticipation.

    Regards,
    Peter.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Adding various cells on a click??

    assign this code to a button
    Public Sub sumcells()
        Dim c As Range
        Dim s
        For Each c In Selection
           If WorksheetFunction.IsNumber(c.Value) Then
             s = s + c.Value
           Else
             s = s & c.Value & " "
           End If
        Next
        Range("G3").Value = s 
        Set c = Nothing
    End Sub
    Last edited by patel45; 08-23-2012 at 02:23 PM.
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    08-17-2012
    Location
    Coventry, UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Adding various cells on a click??

    Dear patel45,

    Many thanks for your reply. Unfortunately I can't get it to work. I attached my spreadsheet this time - would you mind having a look and see if you could run this? Your help is greatly appreciated!
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Adding various cells on a click??

    Public Sub sumcells()
        Dim c As Range
        Dim s
        For Each c In Selection
           If WorksheetFunction.IsNumber(c.Value) Then
             s = s + c.Value
             arow = c.Row
           Else
             s = s & c.Value & " "
           End If
        Next
        Range("X" & arow).Value = s
        Set c = Nothing
    End Sub
    but works only with selected cells, not with blue cells
    Last edited by patel45; 08-25-2012 at 05:17 AM.

  5. #5
    Registered User
    Join Date
    08-17-2012
    Location
    Coventry, UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Adding various cells on a click??

    Thanks for getting back to me patel45. Unfortunately I still can't get it to work??? I'm new to VBA in Excel so perhaps I'm missing something here? Would you be able to attach the file that you've managed to get to work?

    Please help...

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Adding various cells on a click??

    No problem, find attached
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    08-17-2012
    Location
    Coventry, UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Adding various cells on a click??

    Right, could you please help me understand how you've managed to select a couple of different cells and calculate the sum in to cell X12?

  8. #8
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Adding various cells on a click??

    to semplify
    Public Sub sumcells()
        Dim c As Range,  s
        For Each c In Selection ' selection is the range of selected cells
             s = s + c.Value ' sum all cells value in selection
             arow = c.Row ' save row
        Next
        Range("X" & arow).Value = s ' display sum
        Set c = Nothing
    End Sub

  9. #9
    Registered User
    Join Date
    08-17-2012
    Location
    Coventry, UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Adding various cells on a click??

    I'm getting there...
    Attached Images Attached Images
    Last edited by tholiver; 09-14-2012 at 01:47 PM.

  10. #10
    Registered User
    Join Date
    08-17-2012
    Location
    Coventry, UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Adding various cells on a click??

    Solved, many thanks for your help patel45!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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