A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Button macro to move/delete active row



 
 
Thread Tools Display Modes
  #1  
Old February 13th, 2010, 09:39 AM posted to microsoft.public.excel.misc
KevHardy
external usenet poster
 
Posts: 36
Default Button macro to move/delete active row

I’m trying to learn from previous mistakes, which mainly seem to be around
not planning well enough ahead and designing code on the fly! So I’m trying
to be pro-active 

Anyway, I’m planning a workbook with three sheets: New, Active and Archive.
The sheets are basically the same with a row of headers at the top with work
details entered in rows beneath.

What I would like to do is have two buttons in the last row of the header
labelled ‘Active’ and ‘Archive’ – having the buttons in the header so that I
don’t have to have a button in each row.

Then have a macro that can identify the active row and copy the entire.row
from ‘New’ to the first empty row in either ‘Active’ or ‘Archive’ depending
on which button is clicked. And then delete the old row from ‘New’ of course.

I have attempted to do this myself using bits of code from other solutions
you have been kind enough to give me here on the forum, but my knowledge of
vba isn’t good enough to be able to unpick them (yet). But in the few weeks
that I’ve been using vba I have learnt so much with your help!

Any help would be much appreciated.
  #2  
Old February 13th, 2010, 10:16 AM posted to microsoft.public.excel.misc
Mike H
external usenet poster
 
Posts: 8,419
Default Button macro to move/delete active row

Hi,

The code for both buttons would be the same apart from the destination sheet
name and I have included both in the code below (one commented out).

Put the buttions on your sheet and assin the code below to each

Private Sub CommandButton1_Click()
If Selection.Rows.Count 1 Then Exit Sub
Set sht = Sheets("Active")
'or
'Set sht = Sheets("Archive")
lastrow = sht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
ActiveCell.EntireRow.Copy _
Destination:=sht.Range("A" & lastrow + 1)
ActiveCell.EntireRow.Delete
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"KevHardy" wrote:

I’m trying to learn from previous mistakes, which mainly seem to be around
not planning well enough ahead and designing code on the fly! So I’m trying
to be pro-active 

Anyway, I’m planning a workbook with three sheets: New, Active and Archive.
The sheets are basically the same with a row of headers at the top with work
details entered in rows beneath.

What I would like to do is have two buttons in the last row of the header
labelled ‘Active’ and ‘Archive’ – having the buttons in the header so that I
don’t have to have a button in each row.

Then have a macro that can identify the active row and copy the entire.row
from ‘New’ to the first empty row in either ‘Active’ or ‘Archive’ depending
on which button is clicked. And then delete the old row from ‘New’ of course.

I have attempted to do this myself using bits of code from other solutions
you have been kind enough to give me here on the forum, but my knowledge of
vba isn’t good enough to be able to unpick them (yet). But in the few weeks
that I’ve been using vba I have learnt so much with your help!

Any help would be much appreciated.

  #3  
Old February 13th, 2010, 10:22 AM posted to microsoft.public.excel.misc
Per Jessen
external usenet poster
 
Posts: 686
Default Button macro to move/delete active row

Hi

I think it is something like this you want:

Sub CopyActive()
Dim DestCell As Range
Set DestCell = Worhskeets("Active").Range("A1").End(xlDown).Offse t(1, 0)
ActiveCell.EntireRow.Copy Destination:=DestCell
ActiveCell.EntireRow.Delete Shift:=xlShiftUp
End Sub

Regards,
Per

"KevHardy" skrev i meddelelsen
...
I’m trying to learn from previous mistakes, which mainly seem to be around
not planning well enough ahead and designing code on the fly! So I’m
trying
to be pro-active 

Anyway, I’m planning a workbook with three sheets: New, Active and
Archive.
The sheets are basically the same with a row of headers at the top with
work
details entered in rows beneath.

What I would like to do is have two buttons in the last row of the header
labelled ‘Active’ and ‘Archive’ – having the buttons in the header so that
I
don’t have to have a button in each row.

Then have a macro that can identify the active row and copy the entire.row
from ‘New’ to the first empty row in either ‘Active’ or ‘Archive’
depending
on which button is clicked. And then delete the old row from ‘New’ of
course.

I have attempted to do this myself using bits of code from other solutions
you have been kind enough to give me here on the forum, but my knowledge
of
vba isn’t good enough to be able to unpick them (yet). But in the few
weeks
that I’ve been using vba I have learnt so much with your help!

Any help would be much appreciated.


  #4  
Old February 13th, 2010, 11:48 AM posted to microsoft.public.excel.misc
KevHardy
external usenet poster
 
Posts: 36
Default Button macro to move/delete active row

Thanks Mike. Nice bit of code!

"Mike H" wrote:

Hi,

The code for both buttons would be the same apart from the destination sheet
name and I have included both in the code below (one commented out).

Put the buttions on your sheet and assin the code below to each

Private Sub CommandButton1_Click()
If Selection.Rows.Count 1 Then Exit Sub
Set sht = Sheets("Active")
'or
'Set sht = Sheets("Archive")
lastrow = sht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
ActiveCell.EntireRow.Copy _
Destination:=sht.Range("A" & lastrow + 1)
ActiveCell.EntireRow.Delete
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"KevHardy" wrote:

I’m trying to learn from previous mistakes, which mainly seem to be around
not planning well enough ahead and designing code on the fly! So I’m trying
to be pro-active 

Anyway, I’m planning a workbook with three sheets: New, Active and Archive.
The sheets are basically the same with a row of headers at the top with work
details entered in rows beneath.

What I would like to do is have two buttons in the last row of the header
labelled ‘Active’ and ‘Archive’ – having the buttons in the header so that I
don’t have to have a button in each row.

Then have a macro that can identify the active row and copy the entire.row
from ‘New’ to the first empty row in either ‘Active’ or ‘Archive’ depending
on which button is clicked. And then delete the old row from ‘New’ of course.

I have attempted to do this myself using bits of code from other solutions
you have been kind enough to give me here on the forum, but my knowledge of
vba isn’t good enough to be able to unpick them (yet). But in the few weeks
that I’ve been using vba I have learnt so much with your help!

Any help would be much appreciated.

  #5  
Old February 13th, 2010, 11:59 AM posted to microsoft.public.excel.misc
Mike H
external usenet poster
 
Posts: 8,419
Default Button macro to move/delete active row

Glad I could help and thanks for the feedback
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"KevHardy" wrote:

Thanks Mike. Nice bit of code!

"Mike H" wrote:

Hi,

The code for both buttons would be the same apart from the destination sheet
name and I have included both in the code below (one commented out).

Put the buttions on your sheet and assin the code below to each

Private Sub CommandButton1_Click()
If Selection.Rows.Count 1 Then Exit Sub
Set sht = Sheets("Active")
'or
'Set sht = Sheets("Archive")
lastrow = sht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
ActiveCell.EntireRow.Copy _
Destination:=sht.Range("A" & lastrow + 1)
ActiveCell.EntireRow.Delete
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"KevHardy" wrote:

I’m trying to learn from previous mistakes, which mainly seem to be around
not planning well enough ahead and designing code on the fly! So I’m trying
to be pro-active 

Anyway, I’m planning a workbook with three sheets: New, Active and Archive.
The sheets are basically the same with a row of headers at the top with work
details entered in rows beneath.

What I would like to do is have two buttons in the last row of the header
labelled ‘Active’ and ‘Archive’ – having the buttons in the header so that I
don’t have to have a button in each row.

Then have a macro that can identify the active row and copy the entire.row
from ‘New’ to the first empty row in either ‘Active’ or ‘Archive’ depending
on which button is clicked. And then delete the old row from ‘New’ of course.

I have attempted to do this myself using bits of code from other solutions
you have been kind enough to give me here on the forum, but my knowledge of
vba isn’t good enough to be able to unpick them (yet). But in the few weeks
that I’ve been using vba I have learnt so much with your help!

Any help would be much appreciated.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:03 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 OfficeFrustration.
The comments are property of their posters.