find and copy last updated row to worksheet

everscern

Board Regular
Joined
Oct 10, 2006
Messages
56
is there any macro which finds the last updated row and copys the selected row to a worksheet (let's say AAA) ?
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

tmcfadden

Board Regular
Joined
Aug 17, 2005
Messages
151
What do you mean by "last updated row"?

How and when is the worksheet updated?

How is the data laid out?

-Tim
 

everscern

Board Regular
Joined
Oct 10, 2006
Messages
56

picture 1



picture 2

the highlighted rows are the last updated rows. Upon clicking a button, I hope the last updated row will be transferred to a worksheet.
 

tmcfadden

Board Regular
Joined
Aug 17, 2005
Messages
151
This is a bit tricky because you have to keep track of the last row that was updated. To do this ( since you can't have global variables ), I created a new worksheet named "Vars". On that worksheet, I have a named range called "LastUpdatedRow".

The code that does the actual copying ( in your case, you might want to do other things with it ) is located in a module. Here's that code:
Code:
Sub CopyLastUpdatedRow()

ActiveSheet.Rows(Sheets("Vars").Range("LastUpdatedRow")).EntireRow.Copy

End Sub

Now we just have to keep that range updated. I put some code in Sheet1's 'Change' event to do just that:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Sheets("Vars").Range("LastUpdatedRow").Value = Target.Row

End Sub

The above code should go into any worksheet that you want to enable this functionality.

Now that we're keeping the value current, I added a command button that would call the function I created ( CopyLastUpdatedRow ):
Code:
Private Sub CommandButton1_Click()
CopyLastUpdatedRow
End Sub

That's it. I can now change the worksheet and hit the command button. The command button calls my specialized function ( which you'll have to change ).

-Tim
 

everscern

Board Regular
Joined
Oct 10, 2006
Messages
56
hi.. I tried using this macro. but i do not know how to get the summarized code ' copylastupdatedrow'. Could u tell me how?

Code:
Private Sub CommandButton1_Click() 
CopyLastUpdatedRow 
End Sub
 

tmcfadden

Board Regular
Joined
Aug 17, 2005
Messages
151
Sorry, I've been out of the office for a while.

Do run that macro, you have to put the routine "CopyLastUpdatedRow" someplace that's visible to the button.

My suggestion would be to add it into a module:
  • Open the worksheet
    Open the VBA Editor ( Tools -> Macro -> VBA Editor )
    Insert a new module ( Insert -> Module )
    Paste the code I gave you into this window

-Tim
 

Watch MrExcel Video

Forum statistics

Threads
1,109,359
Messages
5,528,228
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top