Thanks Jim and Dave for all your help! Yes, I did make two mistakes.
1) As you suspected, I deleted the "With Sheets("Sheet1").Cells" line.
2) Also, I used an incomplete string for the search, which it
apparently refused to find. For example
Set rngStart = .Find(What:="XX", _ 'is what I used,but
I should have told it to search for everything in the cell, such as
Set rngStart = .Find(What:="XXYYZZ", _ 'the complete cell content
Dave Peterson wrote:
I bet you changed something in Jim's suggested code that broke the procedure.
You may want to try again or post your current code.
And don't delete that "With Sheets("Sheet1").Cells" line. But do change it to
the correct worksheet name.
David Godinger wrote:
I got a Visual Basic error when I tried to run this code.
Compile error: Invalid or unqualified reference
(By the way, when the code came up on screen, ".Find" was highlighted.)
- - -
Under Help, I got the following:
Invalid or unqualified reference
An identifier beginning with a period is valid only within a With
block. This error has the following cause and solution:
The identifier begins with a period.
Complete the qualification of the identifier or remove the period.
Jim Thomlinson wrote:
Something like this...
Sub PrintRange()
Dim rngStart As Range
Dim rngEnd As Range
With Sheets("Sheet1").Cells 'Change this to suit
On Error Resume Next
Set rngStart = .Find(What:="XX", _
LookAt:=xlWhole, _
LookIn:=xlFormulas, _
MatchCase:=False)
If rngStart Is Nothing Then Exit Sub
Set rngEnd = .Find(What:="YY", _
LookAt:=xlWhole, _
LookIn:=xlFormulas, _
MatchCase:=False)
If rngEnd Is Nothing Then Exit Sub
End With
Range(rngStart, rngEnd).PrintOut
End Sub
--
Please delete "ANTI-SPAM" from email address
David Godinger: Go player, student of Mahatma Gandhi, the Buddha, and Dr. Martin King
--
Please delete "ANTI-SPAM" from email address
David Godinger: Go player, student of Mahatma Gandhi, the Buddha, and Dr. Martin King