Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-28-2014, 04:51 AM
jamierbooth jamierbooth is offline Deleting info from specific table cells Windows XP Deleting info from specific table cells Office XP
Novice
Deleting info from specific table cells
 
Join Date: Feb 2011
Posts: 4
jamierbooth is on a distinguished road
Default Deleting info from specific table cells

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
To add a bit more:

- 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.
Reply With Quote
  #2  
Old 07-28-2014, 10:35 PM
macropod's Avatar
macropod macropod is offline Deleting info from specific table cells Windows 7 32bit Deleting info from specific table cells Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 07-29-2014, 02:04 PM
jamierbooth jamierbooth is offline Deleting info from specific table cells Windows XP Deleting info from specific table cells Office XP
Novice
Deleting info from specific table cells
 
Join Date: Feb 2011
Posts: 4
jamierbooth is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 07-29-2014, 03:20 PM
macropod's Avatar
macropod macropod is offline Deleting info from specific table cells Windows 7 32bit Deleting info from specific table cells Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
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
Deleting info from specific table cells Deleting A blank Line that has a specific heading style , word 2010 & 2013 SteveWcg Word 5 01-08-2014 10:37 PM
Deleting info from specific table cells Deleting rows with specific criteria joflow21 Excel 9 11-22-2013 12:10 PM
Deleting info from specific table cells Save table sytle, NOT a specific table Lebber Word 9 02-01-2013 12:31 AM
Deleting info from specific table cells how to transfer multiple excel cells into specific place in word document by formulas anton Excel 1 12-20-2011 03:56 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft