Delete Row

M

magmike

If I were to create a button in a template row for the purpose of deleting that row if the button was pressed, what would be the best way to write that code?

Thanks in advance for your help,

magmike
 
G

GS

If I were to create a button in a template row for the purpose of
deleting that row if the button was pressed, what would be the best
way to write that code?

Thanks in advance for your help,

magmike

Why not simply right-click the row header and choose 'Delete'?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
M

magmike

Why not simply right-click the row header and choose 'Delete'?



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion

Because there is a button that adds rows to ensure the formatting and such remains in tact. Therefore, having a button to delete the inserted row would maintain the flow I have created. Plus, the traditional way involves right-click, move mouse to selection, then left-click which is three moves whereas a macro button is one move. Did I just admit that I am lazy?

PS: the command button would be on the row in question so if basing the removal on the selection, it would first need to select the same row that the button is on, just in case something else was currently selected.
 
G

GS

Because there is a button that adds rows to ensure the formatting and
such remains in tact. Therefore, having a button to delete the
inserted row would maintain the flow I have created. Plus, the
traditional way involves right-click, move mouse to selection, then
left-click which is three moves whereas a macro button is one move.
Did I just admit that I am lazy?

PS: the command button would be on the row in question so if basing
the removal on the selection, it would first need to select the same
row that the button is on, just in case something else was currently
selected.

If you're implying that every formatted row has a delete button.., well
that;s just asking for trouble! Otherwise, how does the button get on
the row?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
M

magmike

If you're implying that every formatted row has a delete button.., well

that;s just asking for trouble! Otherwise, how does the button get on

the row?



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion

You are correct - it would be part of the template. What kind of trouble?
 
G

GS

You are correct - it would be part of the template. What kind of

How many buttons do you think might end up on a single sheet this
template row is copied to? It would be better, IMO, to disguise a cell
in colA to look like a button so when clicked (selected) that sheet's
event code can fire the delete action on that row.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
G

GS

You are correct - it would be part of the template. What kind of
How many buttons do you think might end up on a single sheet this
template row is copied to? It would be better, IMO, to disguise a
cell in colA to look like a button so when clicked (selected) that
sheet's event code can fire the delete action on that row.

Here's the code...

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
With Target
If .Column = 1 And .Value = "X" Then .EntireRow.Delete
End With 'Target
End Sub

...and the cell is sized square, centered h/v, boldface, dark red, and
has solid border right/bottom.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
M

magmike

Here's the code...



Option Explicit



Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error Resume Next

With Target

If .Column = 1 And .Value = "X" Then .EntireRow.Delete

End With 'Target

End Sub



..and the cell is sized square, centered h/v, boldface, dark red, and

has solid border right/bottom.



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion

Maybe 15 at the max. It is for line items in a quote. How would this print?
 
M

magmike

Here's the code...



Option Explicit



Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error Resume Next

With Target

If .Column = 1 And .Value = "X" Then .EntireRow.Delete

End With 'Target

End Sub



..and the cell is sized square, centered h/v, boldface, dark red, and

has solid border right/bottom.



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion

PS: It is a tiny button just big enough to be labeled "x"
 
G

GS

Maybe 15 at the max. It is for line items in a quote. How would this

Well you don't want to include colA (or whatever col used for this) in
the Print_Area to NOT print it. Though I can't imagine why you'd want
to delete line items from a quote sheet!!

Not sure how your template is[are] designed but here's how I handled
this in a quotation app I did for a client in Michigan...

Col labeled "Qty" accepted a Qty
Col labeled "Amount" formula is "=Qty*UnitPrice"
Col labeled "Print" got 'flagged' when Qty received a numeric value.

The template (one for each of 21 product lines) contained line items
for every conceivable option/choice available for the product the
template was made for. This could be 100s of rows but users (sales reps
for the client) could choose to print the entire sheet or just
'selected items'. In the case of the latter non-selected item rows were
hidden, leaving only the default rows and selected items to print. The
reason I did it this way is so users could 'adjust' existing quotes
without losing any line items on the sheet. This allowed revision on
demand before a sales rep converted the quote to a 'Sales Order' where
the hidden 'Signatures' range at the bottom of the line items total was
viewable/printable. Once the sales rep obtained a signature from the
customer, that same SO was converted to a 'Purchase Order' and emailed
to my client.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
G

GS

PS: It is a tiny button just big enough to be labeled "x"

Doesn't matter what size any controls on a worksheet are! Troubles
arise because they exist in scrollable areas, regardless if they're
Form or ActiveX!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
G

GS

You are correct - it would be part of the template. What kind of
Here's the code...

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
With Target
If .Column = 1 And .Value = "X" Then .EntireRow.Delete
End With 'Target
End Sub

..and the cell is sized square, centered h/v, boldface, dark red, and
has solid border right/bottom.

Boldface & dark red apply to font. The cell is shaded 50% grey so it
looks like a button after the 2 borders are added.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
G

GS

I like the control this gives over the previous suggestion...


Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
On Error Resume Next
With Target
If .Column = 1 And .Value = "X" Then _
Cancel = True: .EntireRow.Delete
End With 'Target
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top