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) ?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

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
eee.jpg

picture 1


bbb.jpg

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
 

Forum statistics

Threads
1,141,139
Messages
5,704,514
Members
421,353
Latest member
jekoxien15

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top