PDA

View Full Version : Issues with range



jojojlj
07-09-2012, 10:06 PM
It keeps saying, "Compile error: Sub or function not defined." VBA claims the error is at the Set rCell = Range("A1:C4"). I'd like to actually use SelectCell to make the range correspond to the entirety of the current cell, and then move the cursor to the beginning of the cell. The last three lines will do the trick for both of these actions, but that's a crude method and I'd like to learn more about Range anyway.

Sub CheckVerseOrder()
Dim sAreaText As String
Dim sCellText As String
Dim iVerse1 As Integer
Dim iVerse2 As Integer
Dim rCell As Range

'Be sure at beginning of cell
Set rCell = Range("A1:C4")
rCell.StartOf
Selection.MoveLeft Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveLeft Unit:=wdCharacter, Count:=1

macropod
07-10-2012, 12:36 AM
In Word, there is no such thing as 'Range("A1:C4")', even if you have a table. To set a range for a series of cells in a table, use something like:
Sub Demo()
Dim Rng As Range
With ActiveDocument
Set Rng = .Range(.Tables(1).Cell(1, 1).Range.Start, .Tables(1).Cell(4, 3).Range.End)
End With
End Sub

jojojlj
07-10-2012, 12:52 PM
So how would I designate the current cell where the cursor is, and then move the cursor to the beginning of that cell in Word? I'm trying to designate a single cell; I picked up the bit about ("A1:C4") from somewhere online and it was probably for Excel. With rCell.StartOf, I was trying to move the cursor to the beginning of the cell but that didn't work. Why not? The code you gave me works well, as shown below, and the error message about Sub or Function Not Defined went away.

Sub CheckVerseOrder()
Dim sAreaText As String
Dim sCellText As String
Dim iChap1 As Integer
Dim iChap2 As Integer
Dim rCell As Range

'Be sure at beginning of cell (assumes selection is in third column)
With ActiveDocument
Set rCell = .Range(.Tables(1).Cell(1, 1).Range.Start, .Tables(1).Cell(3, 3).Range.End)
End With
'Set rCell = ActiveDocument.Range.SelectCell
rCell.StartOf
Selection.MoveLeft Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveLeft Unit:=wdCharacter, Count:=1
End Sub

macropod
07-10-2012, 02:35 PM
Without knowing what you're trying to achieve, it's hard to give specific advice. As a rule, though, you rarely need to work with selections or to move a selection.

That said, if you need to work with a cell at the current insertion point, you could use code like:
With Selection
If .Information(wdWithInTable) Then
.Cells(1).Range.InsertBefore "Hello"
End If
End With
Note that the code includes error-checking and the selection isn't moved.

jojojlj
07-11-2012, 09:05 PM
By the way, I'm quite a newbie so a general VBA instruction manual would be welcome if you know of a good one.

Ok, I'll tell you in more detail what I'm trying to do. I'm helping my dad make a concordance of the New Testament. There are English words in the first column, the corresponding Greek words in the second column, and the verse references in the third column. For some words, like "Spirit" or "Christ" there's a gazillion references. So me and my dad want to check that we've entered the references correctly. The books of the Bible, the chapters in each book, and the verse numbers all have to be in the correct order and we have to avoid accidental repetition. Currently I'm trying to check the order of verse numbers. For example, "apostle".

apostle
apóstolos
Matt. 10:2; Acts 2:42; 15:2; Rom. 1:1; 1 Cor. 1:1; 9:1; 12:28; 2 Cor. 1:1; 8:23; 11:5, 13; Eph. 3:5; Phil. 2:25

These are all arranged in a huge table in Word, over 100 pages long. I want to check that it's not 2 Cor. "11:13, 5" because that would be the wrong order (it's really 11:5 and 11:13 but we abbreviate it for convenience). I need to start at the beginning of the cell to do the error-checking so that no matter where in the cell the user clicks, the program will search that entire cell starting at the beginning. The program will then move down a row to the next cell, and again start at the beginning of the new cell (I can't just say arrow down one because then it might land in the middle of the new cell).

For the checking, I could tell Word to find a comma, capture the number before the comma, then compare it to the number after the comma. But how would I do that comparison without using selections?

macropod
07-12-2012, 12:23 AM
You do realize you're reinventing the wheel here, don't you??!! See, for example:
• http://lexicon.katabiblon.com/index.php?, where you can input any form of any Greek word and get a listing of every form of that word, with parsing, by NT & OT (LXX) verse.
• http://biblos.com/, where you can input any verse reference and obtain numerous trnalslations plus full Hebrew/Greek parsing of every word in the verse, and more
• http://www2.mf.no/bibel/vines.html, for Vine's Expository Dictionary of New Testament Words
• http://www.semanticbible.com/hyperconc/hyperconc-home.html, for an ESV NT Concordance
See also:
http://www.biblegateway.com/
http://www.blueletterbible.org/
http://unbound.biola.edu/
http://preceptaustin.org/

The first site alone will supply all the info you need for the validation (though not necessarily in verse order given the different word forms). With ἀπόστολος (apostolos), for example, you'll get the references for all the inflections: ἀπόστολοι, ἀποστόλοι, ἀπόστολον, ἀπόστολος, ἀποστόλου, ἀποστόλους and ἀποστόλων. You can copy & paste the verse references as plain text into word, convert them to a one-column table with one row per verse reference, then sort the table. All the references will then be sorted alpha-numerically by book & verse.

jojojlj
07-15-2012, 02:44 PM
Wow, I'm surprised you know so much about the subject. The sites you mentioned will most likely be useful although I already knew about a few of them. Many sites don't include any of the diacritical (inflection) markings so it's good to find some sites that do.

The reason we're not reinventing the wheel is we're actually making a concordance of the footnotes in the New Testament, for a new version of the Bible, instead of for the actual verses. The name of the version is the Recovery Version, and it's posted online at online.recoveryversion.org. They also give out free hardcopies at bfa.org if you're interested. I felt like I wouldn't need to include the detail about the footnotes in my previous posting.

I will be taking a weeklong vacation so I won't be working on this project until that's over; I probably won't be able to look at anything you post until after my vacation. Thanks for all your help so far!