![]() |
|
#1
|
|||
|
|||
![]()
Hi world.... I'm having trouble getting some code to work. (obviously, or I wouldn't be writing this!) To try and de-clutter an already enormous form....
From a command button, a table is copied and pasted below the existing table and I also want to remove the contents of selected cells. I've cobbled together some code that copies and pastes, and found somewhere that tells me what code to use to delete cell contents, however this bit isn't working for me. Code is below, I've commented out the delete bit that isn't working. Code:
Private Sub cmdBookings_Click() With ActiveDocument .Tables(23).Range.Copy .Range.Select Selection.GoTo what:=wdGoToBookmark, Name:="AfterTable23" Selection.MoveUp Selection.Paste Selection.GoTo what:=wdGoToBookmark, Name:="AfterTable23" Selection.MoveUp Selection.InsertBreak Type:=wdSectionBreakContinuous 'ActiveDocument.Tables(23).Cells(1, 2).Select 'Selection.Delete End With End Sub - User completes form - this particular table (23) shows accommodation bookings. - User will need to come back to form to add further bookings. - User then would (when it works) click button to send old info to bottom in a new table and clear out the existing table for another booking. - User may need to add 3 or 4 accommodation bookings within same form. Any help would be great. Also I struggle to understand the .Cells(1, 2) bit. How does that address the particular cell. Row 1, column 2 ?? or am I barking up the wrong tree? Thanks!!!! Jamie. |
#2
|
||||
|
||||
![]()
All those Selection statements make my eyes water. You could do all of this without selecting anything...
Be that as it may, the simple remedy for your commented-out lines is: ActiveDocument.Tables(23).Cell(1, 2).Range.Text = vbNullString
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Yes I can see how! I've got section breaks and bookmarks etc, it looks a mess but it works up to this point. This is my first real go at vba for Word - I'm more used to vba for Access. Since this is the only bit of vba required for this form, I'm not too fussy about how I acheive the copy and pasting of the table and clearing of the selected cells, so long as it works.
Also, how do I pick out the 4 or 5 individual cells that I need to clear? (ie in excel it would be B2, B3, A5 and so on.) Thanks. Jamie. |
#4
|
||||
|
||||
![]()
When processing multiple cells, you need to supply their row & column addresses. Word VBA doesn't use 'A1'-referencing, perhaps because it provides the ability to merge & split cells in a far more extensive manner than is possible with Excel.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Populate Cells with info contained in other cells | EC37 | Excel Programming | 8 | 07-16-2014 10:55 AM |
![]() |
SteveWcg | Word | 5 | 01-08-2014 10:37 PM |
![]() |
joflow21 | Excel | 9 | 11-22-2013 12:10 PM |
![]() |
Lebber | Word | 9 | 02-01-2013 12:31 AM |
![]() |
anton | Excel | 1 | 12-20-2011 03:56 AM |