Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-13-2022, 12:22 AM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with a script, Range to select as of row 1 and column 2 to the end of the table Windows 10 Help with a script, Range to select as of row 1 and column 2 to the end of the table Office 2019
Competent Performer
Help with a script, Range to select as of row 1 and column 2 to the end of the table
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Lightbulb Help with a script, Range to select as of row 1 and column 2 to the end of the table

Hello Pros,


I've been trying all day to figure out how to select from all tables the range as of rows(1) and Column(2), till the end of the table, on all tables.

I found a script where I've modified it with my needs How to select a range of the second row to the last row Word VBA - Stack Overflow

Where I've coded this script which works well for 1 table:

Code:
Dim aTbl As Table

Set aTbl = ActiveDocument.Tables(1)
Dim NewTable As Boolean

'if not new Table Select All but first row, Else Select whole table
If NewTable = 0 Then
  With aTbl
    ActiveDocument.Range(.Cell(1, 2).Range.Start, .Rows(.Rows.Count).Range.End).Select
  
  End With
  
 Else
  aTbl.Select
End If

  On Error GoTo 0
******************************
However, when applied too all table, I've modified it to this script:

Code:
Dim xTbl As Table

    For Each xTbl In ActiveDocument.Tables
  Dim NewTable As Boolean

'if not new Table Select All but first column, Else Select whole table
 If NewTable = 0 Then
  With xTbl
    ActiveDocument.Range(.Cell(1, 2).Range.Start, .Rows(.Rows.Count).Range.End).Select
  End With
  
 Else
  xTbl.Select
 End If

 Next xTbl

  On Error GoTo 0
When using this code, it selects the very last table of the document.

To test potential scripts, I've used 5 columns and 5 rows, x5 tables.

Any idea how to fix this issue?

I would be sooooooooo greatful for any insights to help me with my script.

Cendrinne
Reply With Quote
  #2  
Old 02-13-2022, 12:41 AM
gmayor's Avatar
gmayor gmayor is offline Help with a script, Range to select as of row 1 and column 2 to the end of the table Windows 10 Help with a script, Range to select as of row 1 and column 2 to the end of the table Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You cannot select non-contiguous ranges with VBA. You should process each table separately.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 02-13-2022, 12:48 AM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with a script, Range to select as of row 1 and column 2 to the end of the table Windows 10 Help with a script, Range to select as of row 1 and column 2 to the end of the table Office 2019
Competent Performer
Help with a script, Range to select as of row 1 and column 2 to the end of the table
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Default Hello Graham, but they will be in a together

It's like, take these below numbers as cells:

1.......2.......3......4.......5
6.......7.......8......9.......10
11.....12.....13.....14.....15
16.....17.....18.....19.....20

So it would be like selecting as of the whole 2nd column to the whole last column.

Does that change your perspective?

Cendrinne
Reply With Quote
  #4  
Old 02-13-2022, 12:57 AM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with a script, Range to select as of row 1 and column 2 to the end of the table Windows 10 Help with a script, Range to select as of row 1 and column 2 to the end of the table Office 2019
Competent Performer
Help with a script, Range to select as of row 1 and column 2 to the end of the table
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Default By the way, I don't understand and thing I don't need the script part of....

The part of the script where it mentioned ''New Table'' and Boolean, I don't know why it's there, don't really get it. I've tried to make a script without it, and kept getting error message, on my side anyway.

So if you find a way without it, it's ok too
Reply With Quote
  #5  
Old 02-13-2022, 02:29 AM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with a script, Range to select as of row 1 and column 2 to the end of the table Windows 10 Help with a script, Range to select as of row 1 and column 2 to the end of the table Office 2019
Competent Performer
Help with a script, Range to select as of row 1 and column 2 to the end of the table
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Default

Oh wait, I think I know how this could be possible. Don't know how to write it though. If it's possible to select all table columns, then it's possible to "De-Select", Column 1.

Or Select all Tables, NOT Column 1.

Think it's doable?
Reply With Quote
  #6  
Old 02-13-2022, 05:13 AM
gmayor's Avatar
gmayor gmayor is offline Help with a script, Range to select as of row 1 and column 2 to the end of the table Windows 10 Help with a script, Range to select as of row 1 and column 2 to the end of the table Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You still have to process each table separately e.g.
Code:
Sub Macro1()
Dim oTable As Table
Dim i As Integer
    For Each oTable In ActiveDocument.Tables
        oTable.Columns(2).Select
        For i = 3 To oTable.Columns.Count
            Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Next i
        'do something with the selection here
    Next oTable    'then move on to the next table
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #7  
Old 02-13-2022, 10:25 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with a script, Range to select as of row 1 and column 2 to the end of the table Windows 10 Help with a script, Range to select as of row 1 and column 2 to the end of the table Office 2019
Competent Performer
Help with a script, Range to select as of row 1 and column 2 to the end of the table
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Red face Hello Graham,

Quote:
Originally Posted by gmayor View Post
You still have to process each table separately e.g.
Code:
Sub Macro1()
Dim oTable As Table
Dim i As Integer
    For Each oTable In ActiveDocument.Tables
        oTable.Columns(2).Select
        For i = 3 To oTable.Columns.Count
            Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Next i
        'do something with the selection here
    Next oTable    'then move on to the next table
End Sub
OK, I didn't know if it was possible or not.
I'll try your latest script and give you news this week.

It's very busy time lately for me, so please accept my appologies in advance for any tardy response.

Have a great week and Thank you sooooooooo much for guiding me. Much much appreciated

Cendrinne
Reply With Quote
Reply

Tags
all tables, help please, range.rows



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with a script, Range to select as of row 1 and column 2 to the end of the table How to script most table column in word document? Cendrinne Word VBA 15 03-22-2021 06:45 PM
Help with a script, Range to select as of row 1 and column 2 to the end of the table Dynamically select a TextBox based on range value IIOII Word VBA 8 07-20-2016 11:28 PM
Help with a script, Range to select as of row 1 and column 2 to the end of the table Help with Index Function to Select Range of Cells bretyuin Excel 1 02-24-2016 05:11 AM
VBA Word Table - Select More than 1 Column at a time - Apply Formatting jc491 Word VBA 12 09-24-2015 06:03 AM
Way to select a range using the mouse on a chart? omahadivision Excel Programming 6 12-29-2012 09:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:54 PM.


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