+ Reply to Thread
Results 1 to 33 of 33

Automatically change cell value based on other cell value

Hybrid View

  1. #1
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Automatically change cell value based on other cell value

    Hi
    I Need Macro Automatically Past Yes Of Cell J To Cell K
    If Cell J Change to yes

    And When Change Cell J to Yes Past Cell D to cell L

    TEST9.jpg

    http://www.2shared.com/file/pBaU8RK-/book1.html
    Last edited by etheer; 11-11-2012 at 05:53 PM.

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    Hello etheer,

    Why a Macro, if you could do it with formulas as per the attached WorkBook?

    Also see the "Please consider" note at the bottom of this post.
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Hi Winon
    Thank you
    but i need macro because i want when change cell J again no do not delete yes and number from cell K and L
    plaese help me if you can

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    Hi etheer,

    But you do say in your first post;

    And When Change Cell J to Yes Past Cell D to cell L
    Maybe we have a misunderstanding here?

    I have entered the formulas on your spreadsheet, See if it is acceptable now.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Thank you so much for your help Winon
    but if change cell J no delete yes and number from cell K and L
    i need when past yes and number in cell K and L do not delete

    i get this macro

    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    ' Code goes in the Worksheet specific module
    Dim rng As Range
    ' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
    Set rng = Target.Parent.Range("J:J")
    ' Only look at single cell changes
    If Target.Count > 1 Then Exit Sub
    ' Only look at that range
    If Intersect(Target, rng) Is Nothing Then Exit Sub
    ' Action if Condition(s) are met (do your thing here...)
    If UCase(Target.Value) = "Yes" Then
    With Target
    .Value = ""
    .Offset(, 1).Value = "Yes"
    Cells(Target.Row, "L").Value = Cells(Target.Row, "D").Value
    
    End With
    End If
    End Sub
    maybe you can edit it for work
    Last edited by etheer; 11-11-2012 at 08:42 PM.

  6. #6
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    I hope you can help me Winon

  7. #7
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    My problems
    1-When cell J change to no delete yes and number from cell K and L
    2- When i change in in cell F,G,H change cell J to yes but do not past yes and number in cell K and L

  8. #8
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    i get this code but not work 100%

    Private Sub Worksheet_Change(ByVal Target As Range)
        Application.ScreenUpdating = False
        If Not Intersect(Target, Range("J:J")) Is Nothing Then
            If Target.Value = "Yes" Then
                Target.Offset(0, 1) = Target
                Target.Offset(0, 2) = Target.Offset(0, -6)
            End If
        End If
        Application.ScreenUpdating = True
    End Sub

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    Hi etheer,

    O.K. Let us try this one. It is still using formulas, but retain the values as long as the Cell/s in Column D has some data.
    Attached Files Attached Files

  10. #10
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    If you prefer the alternative code then copy this Code over mine.

    Just remember that with any one of the two solutions you have now, the code will only work in the Row where you change any cell in Column D.

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
        If Not Intersect(Target, Range("D:D")) Is Nothing Then
            If Target.Offset(0, 6).Value <> "" Then
                Target.Offset(0, 7) = Target.Offset(0, 6)
                Target.Offset(0, 8) = Target
            End If
        End If
        Application.ScreenUpdating = True
    
    
    End Sub

  11. #11
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    I wait someone help me

  12. #12
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    Have you tried the WorkBook in Post no. 9? Or the code in Post no. 10? If you tell us what you don't like about it, then maybe someone help you.

  13. #13
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Hi
    I found code work very good but i need edit it with this sheet
    Please help me

    http://www.2shared.com/file/p4jlW0Rl/Book1.html

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    If you like that Code, then based on the Sample WorkBook in Post Number 9, use it like this:

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range
    If Not Intersect(Target, Range("H:F")) Is Nothing Then
            On Error Resume Next
    For Each c In Range("J7:J" & Cells(Rows.Count, "J").End(xlUp).Row)
            If c = "Yes" Then
                With c
                    .Offset(, 1).Value = "Yes"
                    .Offset(, 2).Value = .Offset(, -6).Value
                End With
            End If
        Next c
        End If
    
    End Sub
    Hope that helps.
    Last edited by Winon; 11-13-2012 at 02:25 AM. Reason: Check the correct Sample WorkBook

  15. #15
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Thank you so much winon yes work code very good
    but i edit

    If Not Intersect(Target, Range("H:F")) Is Nothing Then

    TO

    If Not Intersect(Target, Range("M:N:O:P")) Is Nothing Then

    And i used formula in cell J

    =IF(AND(M7>=50%;N7>50%;O7>0%;P7>-30%;F7>0.2;X7<10%;Y7<10%);"Yes";"No")


    good ?

  16. #16
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    Hello etheer,

    You can change this line:

    If Not Intersect(Target, Range("M:N:O:P")) Is Nothing Then
    to

    If Not Intersect(Target, Range("M:P")) Is Nothing Then
    or to any other Range which you would like the Code to respond to, when you change any Data.

    Your Formula in Column J has no effect on the "Intersect Target Range".
    Last edited by Winon; 11-13-2012 at 01:06 PM. Reason: Sentence structure

  17. #17
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Quote Originally Posted by Winon View Post
    Hello etheer,

    You can change this line:



    to



    or to any other Range which you would like the Code to respond to, when you change any Data.

    Your Formula in Column J has no effect on the "Intersect Target Range".
    Thank you so much winon now work code very good

  18. #18
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Winon i have ask

    I can found code or edit code delete yes and number every new month

    Impossible ?

  19. #19
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    No it is not Impossible,

    What do you want to delete? Make sample and show me.

  20. #20
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    I have problem in code when i change manual in cell H:F
    work code very good but i take data from website if change data in cell H:F not work code

    i want cry please help me

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range
    If Not Intersect(Target, Range("H:F")) Is Nothing Then
            On Error Resume Next
    For Each c In Range("J7:J" & Cells(Rows.Count, "J").End(xlUp).Row)
            If c = "Yes" Then
                With c
                    .Offset(, 1).Value = "Yes"
                    .Offset(, 2).Value = .Offset(, -6).Value
                End With
            End If
        Next c
        End If
    End Sub

  21. #21
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Please test this sheet when i change in sheet M2 not work code
    Attached Files Attached Files

  22. #22
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    Hello etheer,

    Use this Code:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range
    If Not Intersect(Target, Range("F:H,M:P")) Is Nothing Then
            On Error Resume Next
    For Each c In Range("J7:J" & Cells(Rows.Count, "J").End(xlUp).Row)
            If c = "Yes" Then
                With c
                    .Offset(, 1).Value = "Yes"
                    .Offset(, 2).Value = .Offset(, -6).Value
                End With
            End If
        Next c
        End If
    End Sub
    Also see "Please consider" at bottom of this post.

  23. #23
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Thank you winon
    You can edit code no need cell F:H,M:P
    My problem now if used keybored and change in cell work code very good but when i take data online and change cell J to yes do not work code

  24. #24
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    Then try it like this:

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range
    
    Application.EnableEvents = False
            On Error Resume Next
    For Each c In Range("J7:J" & Cells(Rows.Count, "J").End(xlUp).Row)
            If c = "Yes" Then
                With c
                    .Offset(, 1).Value = "Yes"
                    .Offset(, 2).Value = .Offset(, -6).Value
                End With
            End If
        Next c
    Application.EnableEvents = True
    End Sub

  25. #25
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    Hello etheer,

    Did you try the Code as per my last post?

  26. #26
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Thank you winon i test code but also not work
    If used keybored in sheet 1 and click enter work code
    If data change automatic and change J to yes not work code
    I do not want to connect sheet with sheet in code
    I know you're tired trying to help me thank you so much winon
    Attached Files Attached Files

  27. #27
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    I edit code to

    Private Sub Worksheet_Calculate()
    Dim c As Range
    Application.EnableEvents = False
            On Error Resume Next
    For Each c In Range("J7:J" & Cells(Rows.Count, "J").End(xlUp).Row)
            If c = "Yes" Then
                With c
                    .Offset(, 1).Value = "Yes"
                    .Offset(, 2).Value = .Offset(, -6).Value
    
                End With
            End If
        Next c
    Application.EnableEvents = True
    End Sub

    work code 100% i have only one problem

    when change any cell to #N/A code work crazy and past yes and number in all cells
    how edit code not work if cells #N/A
    Last edited by etheer; 11-19-2012 at 03:55 PM.

  28. #28
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    Hi etheer,

    Sorry, but I was away on renovating a house. Please try this formula in Column J with my sample code as per Post No. 28.

    =IF(ISNA(AND(M7>=50%,N7>50%,O7>0%,P7>-30%,F7>0.2,X7<10%,Y7<10%)=TRUE),"",IF(AND(M7>=50%,N7>50%,O7>0%,P7>-30%,F7>0.2,X7<10%,Y7<10%)=TRUE,"Yes","No"))
    Last edited by Winon; 11-23-2012 at 12:07 PM. Reason: Forgot to add the formula.:(

  29. #29
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    i change line

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range

    TO

    Private Sub Worksheet_Calculate()
    Dim c As Range

    I hope now work good

  30. #30
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    I was thinking about the calculate aspect as well.

    So try this:

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range
    
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
            On Error Resume Next
    For Each c In Range("J7:J" & Cells(Rows.Count, "J").End(xlUp).Row)
            If c = "Yes" Then
                With c
                    .Offset(, 1).Value = "Yes"
                    .Offset(, 2).Value = .Offset(, -6).Value
                End With
            End If
        Next c
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
    End Sub

  31. #31
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Hi Winon
    I have ask

    Private Sub Worksheet_Calculate()
    Dim c As Range
    
    Application.EnableEvents = False
            On Error Resume Next
    For Each c In Range("I7:I" & Cells(Rows.Count, "I").End(xlUp).Row)
            If c = "Yes" Then
                With c
                    .Offset(, 1).Value = "Yes"
                    .Offset(, 2).Value = .Offset(, -7).Value
                    .Offset(, 3).Value = .Offset(, -6).Value
                    .Offset(, 4).Value = .Offset(, -5).Value
                    .Offset(, 5).Value = .Offset(, 14).Value
                    .Offset(, 6).Value = .Offset(, 15).Value
                    .Offset(, 7).Value = .Offset(, 16).Value
                    .Offset(, 8).Value = .Offset(, 17).Value
                    .Offset(, 9).Value = .Offset(, 18).Formula
                    .Offset(, 10).Value = .Offset(, 19).Formula
                    .Offset(, 11).Value = .Offset(, 13).Value
                End With
            End If
        Next c
    Application.EnableEvents = True
    End Sub

    can edit code if cell AD change to No
    change

    .Offset(, 9).Value = .Offset(, 18).Formula
    .Offset(, 10).Value = .Offset(, 19).Formula
    To past Value

  32. #32
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically change cell value based on other cell value

    Hello etheer,

    Have you changed your Workbook layout?

    I am totally confused with you referencing Column I which is Empty, and where does Column "AD" come from now, or do you actually mean Columns A & D?

    Maybe it would be better if you upload your "New" sample WorkBook again so that we can have a look at it for you.

  33. #33
    Registered User
    Join Date
    12-09-2011
    Location
    saudia
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Automatically change cell value based on other cell value

    Hi Winon
    Why only code works when the show sheet if hidden or do not show it the code does not work

+ 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