Results 1 to 1 of 1

Looping through cells in a range

Threaded View

  1. #1
    Registered User
    Join Date
    07-06-2012
    Location
    Tennessee
    MS-Off Ver
    2007(PC), 2008(Mac)
    Posts
    7

    Looping through cells in a range

    Attached you will find the file with my issue. I am trying to create a "log" Sheet to keep up with changes on the worksheet with VBA because Built-In Change Tracking is not quite robust enough for my purposes. I'm not great with VBA but figuring out a little as I go along.

    Problem 1: Copy and paste 2 cells over two cells and only the value out of one cell is returned to previousvalue. Same goes for new value.
    Problem 2: If I insert/delete a row or column, the macro goes into infinite loop.
    Problem 3: If I select the entire sheet to make a formatting change or something, I get a Run Time Error 7: Out of Memory Error.
    Dim PreviousValue
    
    Private Sub Worksheet_Change(ByVal Target As Range)
     
     For Each TheCell In Target.Cells
          Worksheets("log").Activate
            Sheets("log").Range("a1").Select
            Sheets("log").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Select
    
                ActiveCell = Target.Address
                ActiveCell.Offset(0, 1) = PreviousValue
                ActiveCell.Offset(0, 2) = Target.Value
        Next
    
        
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        PreviousValue = Target.Value
    End Sub
    Attached Files Attached Files

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