View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Button to move row and delete old row

yes, if the worksheet is protected you can not add or change much
under vba help index search protect, unprotect, you can do it
programmatically then turn it back on when you are finished with your adding
rows

to find the last row
use

activesheet.usedrange.rows.count

adding one to that will give you the first avialable empty row

as for adding to top
try first inserting a row
selecting the inserted row and then pasting your data to the blank row

"Stacie Fugate" wrote:

Also, is there a way to get it to still do this with the top 3 rows being
locked when the sheet is proctected? The way it is set up is that the users
cannot modify the header (the top 3 rows) any, they cannot add any columns,
etc..., they can only add and modify data below the first 3 rows. When I
protected the sheet again, the button didnt work, and it gave me the
debugger... any clues why it does that?

"nippetee" wrote:

sometimes excel has no clue what sheet to do things coded even though it
seems clear to coder... :)

try put activesheet before that range line like this:

ActiveSheet.Range("A4").Select

This should work...

"Stacie Fugate" wrote:

I've created a button at the top of a spreadsheet that says "Move Row to
Tracking Tab". When this button is clicked, I want it to move the current
row (where their cursor is), to the Tracking Tab, and add it either at the
top of the spreadsheet (under the header row) or to the very bottom, while at
the same time, it deletes the old row from the first sheet entirely. The
first cell that contains data on the Tracking Tab is A4. Everything above
that is the header. (And just in case you need to know, the first tab is
titled "Western", and they are the only 2 tabs in the workbook) I've tried
the following code, but cant get it to work out right. It's giving me fits
with the line "Range("A4").Select", and I'm not really sure why.

Here is the code I used:

Private Sub MoveRow_Click()
ActiveCell.EntireRow.Copy
Worksheets("Tracking").Activate 'the other sheet
Range("A4").Select
ActiveCell.Insert Shift:=xlShiftDown
Worksheets("Western").Activate 'back to the original
ActiveCell.EntireRow.Delete Shift:=xlShiftUp
End Sub