+ Reply to Thread
Results 1 to 22 of 22

automatically change all cell values based on updated entry

Hybrid View

  1. #1
    Registered User
    Join Date
    12-26-2012
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    38

    Question automatically change all cell values based on updated entry

    I need help:

    How to do this:
    If I change any value on column C, then it will automatically change all cell value on column C with the updated value based on same criteria on column B

    like I have column b12 value as Test a then I change the value on c12 from 20 to 23, how to make automatic change on all value on c which have same criteria with b12 to the updated value (23)??

    please help

    Thank you
    Attached Files Attached Files

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: automatically change all cell values based on updated entry

    Right click the sheet tab and select vie code and copy and paste the below code

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
    Dim nEndRw As Long, vColB As Variant, i As Long
    
    nEndRw = Cells(Rows.Count, "B").End(xlUp).Row
    vColB = Target.Offset(0, -1).Value
    Application.EnableEvents = False
    
    For i = 1 To nEndRw
        If Cells(i, "B").Value <> "" Then
            If Cells(i, "B").Value = vColB Then
                Cells(i, "C").Value = Target.Value
            End If
        End If
    Next i
    
    Application.EnableEvents = True
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    12-26-2012
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    38

    Thumbs up Re: automatically change all cell values based on updated entry

    thank you so much Mr. Sixthsense, it works like a charm. one more thing, how to make it works for all sheets at once??
    Thank you again, you're the man.
    Last edited by ruliansyah; 01-31-2013 at 10:42 PM.

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: automatically change all cell values based on updated entry

    Glad it helps you and thanks for the feedback

    Just a first line has been changed in the below code, DELETE the previous code from the sheet event code. The below code should be pasted in THISWORKBOOK code window. Refer the below to know how to add the code in THISWORKBOOK CODE window.

    To add code in ThisWorkbook Code Window
    1. Copy the below code
    2. Select the workbook in which you want to store the code
    3. Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    4. In the Project Explorer, find your workbook, and open the list of Microsoft Excel Objects
    5. Right-click on the ThisWorkbook object, and choose View Code
    6. Where the cursor is flashing, choose Edit | Paste

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
    Dim nEndRw As Long, vColB As Variant, i As Long
    
    nEndRw = Cells(Rows.Count, "B").End(xlUp).Row
    vColB = Target.Offset(0, -1).Value
    Application.EnableEvents = False
    
    For i = 1 To nEndRw
        If Cells(i, "B").Value <> "" Then
            If Cells(i, "B").Value = vColB Then
                Cells(i, "C").Value = Target.Value
            End If
        End If
    Next i
    
    Application.EnableEvents = True
    
    End Sub
    Last edited by :) Sixthsense :); 01-31-2013 at 11:57 PM.

  5. #5
    Registered User
    Join Date
    12-26-2012
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    38

    Re: automatically change all cell values based on updated entry

    Ok mr. sixthsense, in that case it will run i change worksheet right?? what if it run automatically without having to change worksheet??

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: automatically change all cell values based on updated entry

    Quote Originally Posted by ruliansyah View Post
    what if it run automatically without having to change worksheet??
    Not sure what you are trying to say by way of the above sentence

  7. #7
    Registered User
    Join Date
    12-26-2012
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    38

    Re: automatically change all cell values based on updated entry

    Works Great, you're the man, you save me thank you so so so much for your help.

    another question,
    Still the same topic but to change the value on column B itself, let say I have some B cell with the value "Test A" then if I change the value in any cell from "Test A" to "Test A1" it would change all "Test A" value on entire B column into "Test A1" and so within another sheet. I believe it use oldvalue method but I don't know how it works.
    Last edited by ruliansyah; 02-01-2013 at 04:00 AM.

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: automatically change all cell values based on updated entry

    Glad it works and thanks for the feedback

  9. #9
    Registered User
    Join Date
    12-26-2012
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    38

    Re: automatically change all cell values based on updated entry

    another question,
    Still the same topic but to change the value on column B itself, let say I have some B cell with the value "Test A" then if I change the value in any cell from "Test A" to "Test A1" it would change all "Test A" value on entire B column into "Test A1" and so within another sheet. I believe it use oldvalue method but I don't know how it works.

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: automatically change all cell values based on updated entry

    Replace the previous code of THISWORKBOOK code with the below one

    Dim vPreValue As Variant
    
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
        vPreValue = Target.Value
    End Sub
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Intersect(Target, Range("B:C")) Is Nothing Then Exit Sub
    Dim Ws As Worksheet, nEndRw As Long, vColB As Variant, i As Long, sCol As String
    
    Application.EnableEvents = False
    
    For Each Ws In ThisWorkbook.Sheets
        With Ws
            nEndRw = .Cells(Rows.Count, "B").End(xlUp).Row
            If Target.Column = 2 Then
                sCol = "B"
                vColB = vPreValue
            Else
                vColB = Target.Offset(0, -1).Value
                sCol = "C"
            End If
            
            For i = 1 To nEndRw
                If .Cells(i, "B").Value <> "" Then
                    If .Cells(i, "B").Value = vColB Then
                        .Cells(i, sCol).Value = Target.Value
                    End If
                End If
            Next i
        End With
    Next Ws
    
    Application.EnableEvents = True
    
    End Sub

  11. #11
    Registered User
    Join Date
    12-26-2012
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    38

    Thumbs up Re: automatically change all cell values based on updated entry

    That is very very very great things ever, It really works... you are the man mr. Sixthsense
    thank you again for your help

  12. #12
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: automatically change all cell values based on updated entry

    Sorry I missed to read the FORMULA Issue, Replace the previous code with the below Revised Code

    Dim vPreValue As Variant
    
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Intersect(Target, Range("B:B")) Is Nothing Then Exit Sub
    vPreValue = Target.Value
    
    End Sub
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Intersect(Target, Range("B:C")) Is Nothing Then Exit Sub
    Dim Ws As Worksheet, nEndRw As Long, vColB As Variant, i As Long
    
    Application.EnableEvents = False
    
    For Each Ws In ThisWorkbook.Sheets
        With Ws
            nEndRw = .Cells(Rows.Count, "B").End(xlUp).Row
            
            If Target.Column = 2 Then
                vColB = vPreValue
            Else
                vColB = Target.Offset(0, -1).Value
            End If
            
            For i = 1 To nEndRw
                If .Cells(i, "B").Value <> "" Then
                    If .Cells(i, "B").Value = vColB Then
                        .Cells(i, Target.Column) = Target
                    End If
                End If
            Next i
        End With
    Next Ws
    
    Application.EnableEvents = True
    
    End Sub

  13. #13
    Registered User
    Join Date
    12-26-2012
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    38

    Re: automatically change all cell values based on updated entry

    mr. Sixthsense, tried the update but still don't work with formula

  14. #14
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: automatically change all cell values based on updated entry

    I believe this will be the Final Code, Replace the previous code with the below:-

    Dim vPreValue As Variant
    
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Intersect(Target, Range("B:B")) Is Nothing Then Exit Sub
    vPreValue = Target.Value
    
    End Sub
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Intersect(Target, Range("B:C")) Is Nothing Then Exit Sub
    Dim Ws As Worksheet, nEndRw As Long, vColB As Variant, i As Long
    
    On Error GoTo ErrorOccurred
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
    For Each Ws In ThisWorkbook.Sheets
        With Ws
            nEndRw = .Cells(Rows.Count, "B").End(xlUp).Row
            
            If Target.Column = 2 Then
                vColB = vPreValue
            Else
                vColB = Target.Offset(0, -1).Value
            End If
            
            For i = 1 To nEndRw
                If .Cells(i, "B").Value <> "" Then
                    If .Cells(i, "B").Value = vColB Then
                        .Cells(i, Target.Column) = Target.Formula
                    End If
                End If
            Next i
        End With
    Next Ws
    
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Exit Sub
    
    ErrorOccurred:
        Application.EnableEvents = True
        Application.ScreenUpdating = True
        MsgBox "An Error Occurred", vbCritical, "Error Alert"
        
    End Sub

  15. #15
    Registered User
    Join Date
    12-26-2012
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    38

    Thumbs up Re: automatically change all cell values based on updated entry

    WOW That is a very perfect mr. Sixthsense... Thank you so much...
    Attached Files Attached Files

  16. #16
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: automatically change all cell values based on updated entry

    Glad it fulfilled your requirement completely

    Once again thanks for the feedback

+ 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