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 Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Delete a column with a checkbox



 
 
Thread Tools Display Modes
  #1  
Old May 6th, 2009, 07:28 PM posted to microsoft.public.word.tables
sg
external usenet poster
 
Posts: 61
Default Delete a column with a checkbox

I have a table that has 3 columns - sometimes I need the last column and
sometimes I don't. Is it possible to put a formfield checkbox at the top of
the column so that if it is not checked, the column will be deleted?

Likewise, some of the rows may be needed, some may not. Can I also put a
checkbox in front of each row to control which can be deleted and which
cannot?
  #2  
Old May 10th, 2009, 08:34 AM posted to microsoft.public.word.tables
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default Delete a column with a checkbox

The problem with doing that sort of thing is that there is no going back if
you change your mind.

The following code run on exit from the checkbox will however give you a
chance to change your mind:

Dim Response
With ActiveDocument
If .FormFields("Check1").CheckBox.Value = True Then
Response = MsgBox("Are you sure that you want to delete the
column?", vbQuestion + vbYesNo)
If Response = vbYes Then
.Unprotect
.Tables(1).Columns(3).Delete
.Protect wdAllowOnlyFormFields, NoReset
End If
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
I have a table that has 3 columns - sometimes I need the last column and
sometimes I don't. Is it possible to put a formfield checkbox at the top
of
the column so that if it is not checked, the column will be deleted?

Likewise, some of the rows may be needed, some may not. Can I also put a
checkbox in front of each row to control which can be deleted and which
cannot?


  #3  
Old May 12th, 2009, 03:07 AM posted to microsoft.public.word.tables
sg
external usenet poster
 
Posts: 61
Default Delete a column with a checkbox

That is awesome. Thank you!

"Doug Robbins - Word MVP" wrote:

The problem with doing that sort of thing is that there is no going back if
you change your mind.

The following code run on exit from the checkbox will however give you a
chance to change your mind:

Dim Response
With ActiveDocument
If .FormFields("Check1").CheckBox.Value = True Then
Response = MsgBox("Are you sure that you want to delete the
column?", vbQuestion + vbYesNo)
If Response = vbYes Then
.Unprotect
.Tables(1).Columns(3).Delete
.Protect wdAllowOnlyFormFields, NoReset
End If
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
I have a table that has 3 columns - sometimes I need the last column and
sometimes I don't. Is it possible to put a formfield checkbox at the top
of
the column so that if it is not checked, the column will be deleted?

Likewise, some of the rows may be needed, some may not. Can I also put a
checkbox in front of each row to control which can be deleted and which
cannot?



  #4  
Old May 15th, 2009, 03:42 AM posted to microsoft.public.word.tables
sg
external usenet poster
 
Posts: 61
Default Delete a column with a checkbox

If I could bother you again...

I tweaked the code you gave me to also delete a row in the same table if the
checkbox is not checked. Is there a way to specify that it should be the row
that the checkbox is in instead of specifying row 2 or row 3?

"Doug Robbins - Word MVP" wrote:

The problem with doing that sort of thing is that there is no going back if
you change your mind.

The following code run on exit from the checkbox will however give you a
chance to change your mind:

Dim Response
With ActiveDocument
If .FormFields("Check1").CheckBox.Value = True Then
Response = MsgBox("Are you sure that you want to delete the
column?", vbQuestion + vbYesNo)
If Response = vbYes Then
.Unprotect
.Tables(1).Columns(3).Delete
.Protect wdAllowOnlyFormFields, NoReset
End If
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
I have a table that has 3 columns - sometimes I need the last column and
sometimes I don't. Is it possible to put a formfield checkbox at the top
of
the column so that if it is not checked, the column will be deleted?

Likewise, some of the rows may be needed, some may not. Can I also put a
checkbox in front of each row to control which can be deleted and which
cannot?



  #5  
Old May 16th, 2009, 08:20 AM posted to microsoft.public.word.tables
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default Delete a column with a checkbox

Selection.Rows(1).Delete

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
If I could bother you again...

I tweaked the code you gave me to also delete a row in the same table if
the
checkbox is not checked. Is there a way to specify that it should be the
row
that the checkbox is in instead of specifying row 2 or row 3?

"Doug Robbins - Word MVP" wrote:

The problem with doing that sort of thing is that there is no going back
if
you change your mind.

The following code run on exit from the checkbox will however give you a
chance to change your mind:

Dim Response
With ActiveDocument
If .FormFields("Check1").CheckBox.Value = True Then
Response = MsgBox("Are you sure that you want to delete the
column?", vbQuestion + vbYesNo)
If Response = vbYes Then
.Unprotect
.Tables(1).Columns(3).Delete
.Protect wdAllowOnlyFormFields, NoReset
End If
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
I have a table that has 3 columns - sometimes I need the last column and
sometimes I don't. Is it possible to put a formfield checkbox at the
top
of
the column so that if it is not checked, the column will be deleted?

Likewise, some of the rows may be needed, some may not. Can I also put
a
checkbox in front of each row to control which can be deleted and which
cannot?




  #6  
Old May 17th, 2009, 02:16 AM posted to microsoft.public.word.tables
sg
external usenet poster
 
Posts: 61
Default Delete a column with a checkbox

Well...I tried that - put it in place of .Tables(1).Rows(2).Delete. I got an
error then that said the requested member of the collection does not exist.
Then I changed the code so it read .Tables(1).Selection.Rows(1).Delete, but I
still get an error.

What am I doing wrong?

"Doug Robbins - Word MVP" wrote:

Selection.Rows(1).Delete

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
If I could bother you again...

I tweaked the code you gave me to also delete a row in the same table if
the
checkbox is not checked. Is there a way to specify that it should be the
row
that the checkbox is in instead of specifying row 2 or row 3?

"Doug Robbins - Word MVP" wrote:

The problem with doing that sort of thing is that there is no going back
if
you change your mind.

The following code run on exit from the checkbox will however give you a
chance to change your mind:

Dim Response
With ActiveDocument
If .FormFields("Check1").CheckBox.Value = True Then
Response = MsgBox("Are you sure that you want to delete the
column?", vbQuestion + vbYesNo)
If Response = vbYes Then
.Unprotect
.Tables(1).Columns(3).Delete
.Protect wdAllowOnlyFormFields, NoReset
End If
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
I have a table that has 3 columns - sometimes I need the last column and
sometimes I don't. Is it possible to put a formfield checkbox at the
top
of
the column so that if it is not checked, the column will be deleted?

Likewise, some of the rows may be needed, some may not. Can I also put
a
checkbox in front of each row to control which can be deleted and which
cannot?




  #7  
Old May 17th, 2009, 09:24 AM posted to microsoft.public.word.tables
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default Delete a column with a checkbox

You need to use:

Dim Response
With ActiveDocument
If .FormFields("Check1").CheckBox.Value = True Then
Response = MsgBox("Are you sure that you want to delete the
column?", vbQuestion + vbYesNo)
If Response = vbYes Then
.Unprotect
.FormFields("check1").Range.Rows(1).Delete
' .Tables(1).Columns(3).Delete
.Protect wdAllowOnlyFormFields, NoReset
End If
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
news
Well...I tried that - put it in place of .Tables(1).Rows(2).Delete. I got
an
error then that said the requested member of the collection does not
exist.
Then I changed the code so it read .Tables(1).Selection.Rows(1).Delete,
but I
still get an error.

What am I doing wrong?

"Doug Robbins - Word MVP" wrote:

Selection.Rows(1).Delete

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
If I could bother you again...

I tweaked the code you gave me to also delete a row in the same table
if
the
checkbox is not checked. Is there a way to specify that it should be
the
row
that the checkbox is in instead of specifying row 2 or row 3?

"Doug Robbins - Word MVP" wrote:

The problem with doing that sort of thing is that there is no going
back
if
you change your mind.

The following code run on exit from the checkbox will however give you
a
chance to change your mind:

Dim Response
With ActiveDocument
If .FormFields("Check1").CheckBox.Value = True Then
Response = MsgBox("Are you sure that you want to delete the
column?", vbQuestion + vbYesNo)
If Response = vbYes Then
.Unprotect
.Tables(1).Columns(3).Delete
.Protect wdAllowOnlyFormFields, NoReset
End If
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
I have a table that has 3 columns - sometimes I need the last column
and
sometimes I don't. Is it possible to put a formfield checkbox at
the
top
of
the column so that if it is not checked, the column will be deleted?

Likewise, some of the rows may be needed, some may not. Can I also
put
a
checkbox in front of each row to control which can be deleted and
which
cannot?





  #8  
Old May 19th, 2009, 03:49 AM posted to microsoft.public.word.tables
sg
external usenet poster
 
Posts: 61
Default Delete a column with a checkbox

Thanks! That is absolutely perfect!!

"Doug Robbins - Word MVP" wrote:

You need to use:

Dim Response
With ActiveDocument
If .FormFields("Check1").CheckBox.Value = True Then
Response = MsgBox("Are you sure that you want to delete the
column?", vbQuestion + vbYesNo)
If Response = vbYes Then
.Unprotect
.FormFields("check1").Range.Rows(1).Delete
' .Tables(1).Columns(3).Delete
.Protect wdAllowOnlyFormFields, NoReset
End If
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
news
Well...I tried that - put it in place of .Tables(1).Rows(2).Delete. I got
an
error then that said the requested member of the collection does not
exist.
Then I changed the code so it read .Tables(1).Selection.Rows(1).Delete,
but I
still get an error.

What am I doing wrong?

"Doug Robbins - Word MVP" wrote:

Selection.Rows(1).Delete

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
If I could bother you again...

I tweaked the code you gave me to also delete a row in the same table
if
the
checkbox is not checked. Is there a way to specify that it should be
the
row
that the checkbox is in instead of specifying row 2 or row 3?

"Doug Robbins - Word MVP" wrote:

The problem with doing that sort of thing is that there is no going
back
if
you change your mind.

The following code run on exit from the checkbox will however give you
a
chance to change your mind:

Dim Response
With ActiveDocument
If .FormFields("Check1").CheckBox.Value = True Then
Response = MsgBox("Are you sure that you want to delete the
column?", vbQuestion + vbYesNo)
If Response = vbYes Then
.Unprotect
.Tables(1).Columns(3).Delete
.Protect wdAllowOnlyFormFields, NoReset
End If
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"sg" wrote in message
...
I have a table that has 3 columns - sometimes I need the last column
and
sometimes I don't. Is it possible to put a formfield checkbox at
the
top
of
the column so that if it is not checked, the column will be deleted?

Likewise, some of the rows may be needed, some may not. Can I also
put
a
checkbox in front of each row to control which can be deleted and
which
cannot?






 




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 04:09 PM.


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