Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    ellisbill
    Guest

    Find Table Cells

    I've read and re-read all the recent discussions on WOW concerning searches and wildcards but still haven't seen the solution to my number 1 search problem. Which is, "How can I find that little, star-like character that designates the end of a cell in a table?"

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Find Table Cells

    Hi WJE,

    If you'll forgive a preliminary question: why are you trying to "Find" it (since it's not editable) - what's the bigger picture of what you're trying to do?

    Regards,
    Gary

  3. #3
    ellisbill
    Guest

    Re: Find Table Cells

    Gary,

    Thanks for the response.

    The problem comes up in many macro situations where to properly edit a table entry; I must position the cursor at the end point. The situation is exactly analogous to finding the paragraph mark.

    Clear?

    Regards,

    WJE

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Find Table Cells

    Hi again,

    I figured that's what you were after, but just wanted to make sure )

    There's probably a really elegant way to do this, but I've never had the lighbulb go off for that one. Instead I take the easy way out with good old simplistic methods like this:

    Selection.MoveRight Unit:=wdCell
    Selection.MoveLeft Unit:=wdCharacter

    (the product of just playing around in the user interface until I find a method that looks like it works)

    (of course, don't run this in the last cell of a table!)

    Hope this helps,
    Gary

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Massachusetts
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Table Cells

    Here's an adaptation of some MS code, to give you an idea how it is done:

    <pre>If Selection.Information(wdWithInTable) Then
    Set myRange = Selection.Range
    Set oTable = myRange.Tables(1)
    For Each aCell In oTable.Range.Cells
    mycell = Selection.Range.End - 1
    'You are now at the end marker of the cell(EOC)
    aCell.Range.InsertAfter "EOC"
    Next aCell
    MsgBox "This Macro Is Finished"
    Else
    MsgBox "You Are Not In A Table"
    End If</pre>


  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Find Table Cells

    Hi James,

    Thanks for this. The Range.InsertAfter is much better. (Range and tables were made for each other [img]/w3timages/icons/love.gif[/img])

    By the way, the "mycell = Selection.Range.End - 1" actually isn't doing anything in this example.

    Gary

  7. #7
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Massachusetts
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Table Cells

    Gary, Thanks, you are of course correct; I was trimming down some code, and did not trim enough [img]/w3timages/icons/smile.gif[/img]

  8. #8
    ellisbill
    Guest

    Re: Find Table Cells

    Gary, James,

    Thanks much guys, I've implemented the code and have learned how to work with it.

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Table Cells

    Hi James:

    I tried your code & got a compile error that a variable was not defined. It stopped at the line

    Set myRange =

  10. #10
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Find Table Cells

    Hi Phil,

    If you have "Option Explicit" at the top of your module, then it's going to choke on undeclared variables such as those in James's code snippet (the variable declarations go at the beginning of the procedure, so they are often going to be missing when bits of procedures are cited).

    Your options are to delete or comment out "Option Explicit" (although having it on as a default is advisable), or option two: provide the missing declarations, for example:

    Dim myRange As Range

    Gary

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Table Cells

    Thanks, Gary. I've added some declarations but the code still doesn't work. I added:
    Dim myRange As Range
    Dim oTable As Range

    However, it then stops at
    oTable.Range.Cells

    saying "method or data member not found".

  12. #12
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Find Table Cells

    Just had a look back at James's code so here you go:

    Dim myRange As Range
    Dim oTable As Table
    Dim aCell As Cell
    Dim myCell As (I'm not sure of this one, would have try it out to see but am taking the quick route right now - you could try Range. If that gives you an error, just define it as Variant (Dim myCell As Variant).

    Rather than paste the above in, try typing them in yourself, and watch what happens with the autocomplete suggstions as you type.

  13. #13
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Table Cells

    Hi Gary:

    I ran the whole macro. Although it didn't produce any errors, it didn't accomplish its purpose. What it did is go through each cell in a table & enter the letters "EOC". Somethings missing, I fear.

  14. #14
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Find Table Cells

    Phil,

    Actually it sounds like the macro is working fine.

    The original request was how to ensure that the insertion point is at the end of a cell.
    James's sample demonstrated a way to accomplish that, and as a bonus showed how to do this to every cell in the table. The "EOC"s were inserted to demonstrate that they were inserted at the end of the cell for each cell.

    To ensure that an insertion took place at the end of only one cell (which may be closer to the original request), the code James posted could be adapted to something like:

    If Selection.Information(wdWithInTable) Then
    Selection.Cells(1).Range.InsertAfter "EOC"
    Else
    MsgBox "You Are Not In A Table"
    End If

    HTH,
    Gary

  15. #15
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Table Cells

    O.K. Thanks, Gary. I guess I was trying to find something different. I was looking for a way to do a Find/Replace using the end of a cell as an anchor. For example, sometimes you're trying to find a format such as the last word in a paragraph & you use:
    [a-zA-Z]{1,}[.,/?/!]^013

    It would be nice to construct similar format for end of cell.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •