+ Reply to Thread
Results 1 to 5 of 5

automatically sum based on certain cell value

Hybrid View

  1. #1
    Registered User
    Join Date
    04-11-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    96

    automatically sum based on certain cell value

    Need VBA code , if column C contains any string having length greater than 2 then Column A value has been added by 20 and displays in Column B. this should apply on whole column ie code applies to whole column.
    Thanks

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: automatically sum based on certain cell value

    Try this:

    Sub RunMe()
    Dim rCell As Range
    
    For Each rCell In Range("C1:C" & Range("C" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeConstants)
        If Len(rCell) > 2 Then
            Range("B" & rCell.Row) = Range("A" & rCell.Row) + 20
        End If
    Next rCell
    
    End Sub

  3. #3
    Registered User
    Join Date
    04-11-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: automatically sum based on certain cell value

    whats wrong with this code

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
    MsgBox ("Value " & Range("A" & Target.Row).Value)
    If Len(Target) > 2 Then
    Range("B" & Target.Row).Value = Range("A" & Target.Row).Value + 20
    End If

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: automatically sum based on certain cell value

    use worksheet_change instead of worksheet_selectionchange

  5. #5
    Forum Contributor
    Join Date
    10-01-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    136

    Re: automatically sum based on certain cell value

    @mubashar ...when posting codes please use code tags around your code

+ 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. I need cell to automatically change color based on date in different cell
    By acooley in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 08-27-2013, 04:55 PM
  2. [SOLVED] How can we trigger a simple macro based on cell value of another cell automatically with
    By omega0010 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-16-2013, 05:02 PM
  3. Replies: 1
    Last Post: 07-02-2013, 08:58 PM
  4. [SOLVED] VBA referring to a different sheet, automatically fill cell based on content of other cell
    By mweick in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 02-06-2013, 11:50 AM
  5. Automatically update a protected cell based on contents of an unprotected cell
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-01-2009, 11:13 AM

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