• Find Table Cells

    Author
    Topic
    #1768188

    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?”

    Viewing 0 reply threads
    Author
    Replies
    • #1778048

      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

      • #1778053

        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

        • #1778054

          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

        • #1778056

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

          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
          • #1778058

            Hi James,

            Thanks for this. The Range.InsertAfter is much better. (Range and tables were made for each other )

            By the way, the “mycell = Selection.Range.End – 1” actually isn’t doing anything in this example.

            Gary

            • #1778090

              Gary, Thanks, you are of course correct; I was trimming down some code, and did not trim enough

            • #1778501

              Hi James:

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

              Set myRange =

            • #1778502

              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

            • #1778505

              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”.

            • #1778528

              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.

            • #1778589

              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.

            • #1778600

              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

            • #1778638

              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.

            • #1778661

              Don’t know if this will work in the context of your wildcard search, but the ASCII character number for the end of cell mark is 7.

              The end of cell mark apparently contains two characters paired somehow: paragraph mark (13) and EOC (7).

              Maybe ^007 will work then?

              For more info see MS KB #Q165928 (apols for no link!).

            • #1778670

              Hi Gary:

              No. I tried ^James Bond & Find/Replace won’t find him. I don’t think you can use Find/Replace with end of cell.

            • #1778671

              007 or Ctrl-G is BEL (or the bleep) . Perhaps you can’t look for a sound??

            • #1778221

              Gary, James,

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

    Viewing 0 reply threads
    Reply To: Find Table Cells

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: