+ Reply to Thread
Results 1 to 6 of 6

2nd Updating Cell with VBA?

Hybrid View

  1. #1
    Registered User
    Join Date
    08-21-2010
    Location
    Omaha, NE
    MS-Off Ver
    Excel 2003
    Posts
    45

    2nd Updating Cell with VBA?

    Hello,

    Whenever cell A1 has a new value, it is recorded in column K. I would like the VBA code to do the same for cell A2 & column L.

    Here is the VBA code that I have used for cell A1:

    '1st
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim AAA As Long
    
    AAA = Range("K" & Rows.Count).End(xlUp).Row
    
    If [A1] <> Range("K" & AAA) Then
        Application.EnableEvents = False
        Range("K" & AAA + 1).Value = [A1].Value
        Application.EnableEvents = True
    End If
    End Sub
    I've attached 2 files.
    The file that ends with an 'a' is works as expected.
    The file ending in 'b' attempts to do the same thing, but twice, acting on two cells at once and gives an error. I'd like to get this to work, in file 'b'.

    Thanks for any help!

    Greg
    Attached Files Attached Files
    Last edited by Greg777; 01-21-2012 at 11:34 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: 2nd Updating Cell with VBA?

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: 2nd Updating Cell with VBA?

    It would look something like this:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim AAA As Long
    Dim BBB As Long
    
    If Not Intersect(Target, Range("A1")) Is Nothing Then
    
        AAA = Range("K" & Rows.Count).End(xlUp).Row
    
        If [A1] <> Range("K" & AAA) Then
            Application.EnableEvents = False
            Range("K" & AAA + 1).Value = [A1].Value
            Application.EnableEvents = True
        End If
        
        Exit Sub
    End If
    
    If Not Intersect(Target, Range("B1")) Is Nothing Then
    
        BBB = Range("L" & Rows.Count).End(xlUp).Row
        
        If [B1] <> Range("L" & BBB) Then
            Application.EnableEvents = False
            Range("L" & BBB + 1).Value = [B1].Value
            Application.EnableEvents = True
        End If
    
        Exit Sub
    End If
    
    End Sub

    Regards, TMS

  4. #4
    Registered User
    Join Date
    08-21-2010
    Location
    Omaha, NE
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: 2nd Updating Cell with VBA?

    It is no longer returning an error, but there is no 2nd value in column L. I've attached a 3rd workbook where Cell A4 can be updated, changing the values in A1 & B1. Maybe there it is lacking the ability to register the change to cells A1 & A2? If I directly change the value of the cells, they will give output individually, but of course that is not sufficient. I'd stuck on this one.
    Attached Files Attached Files

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: 2nd Updating Cell with VBA?

    You can't have two Worksheet Change Events. You need to combine the code into one module.

    Test which cell has been changed at the beginning of the code and use If or Select Case to execute the appropriate code for that cell.


    Regards, TMS

  6. #6
    Registered User
    Join Date
    08-21-2010
    Location
    Omaha, NE
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: 2nd Updating Cell with VBA?

    OK. Looks like this one isn't possible in Excel. Closing thread.

+ 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