PDA

View Full Version : Solved: Need help with setting a range to some text.



pglufkin
03-25-2013, 12:53 PM
I need help with a procedure to set a range (text_text) for a portion of text contained within multiple adjacent vertical cells. I have a series of an indefinite number of adjacent vertical cells with a special character at the end of the last cell at the end of the text to signal the end of the range. Text are sentences of a paragraph lets say with each cell containing one or more sentences. Paragraph (range I want to set) can be anywhere from one cell to many cells in number. Special character ₱ is the very last character of the last cell of the range. Please find attached sample file. Thank you.

GarysStudent
03-25-2013, 04:45 PM
How about:

Sub marine()
Dim N As Long, NN As Long
Dim reg As Range, s As String
N = Cells(Rows.Count, 1).End(xlUp).Row
For NN = 1 To N
s = Cells(NN, 1).Value
If Asc(Right(s, 1)) = 63 Then
Set reg = Range("A1:A" & NN)
Exit For
End If
Next NN
MsgBox reg.Address
End Sub

pglufkin
03-25-2013, 04:51 PM
Thanks, the only thing I would like to see is the range would start wherever my cursor is sitting once the process begins as the beginning of the range. Thx again.

GarysStudent
03-25-2013, 08:04 PM
A very simple mod:



Sub marine()
Dim N As Long, NN As Long
Dim M As Long
Dim reg As Range, s As String
N = Cells(Rows.Count, 1).End(xlUp).Row
M = ActiveCell.Row
For NN = M To N
s = Cells(NN, 1).Value
If Asc(Right(s, 1)) = 63 Then
Set reg = Range("A" & M & ":A" & NN)
Exit For
End If
Next NN
MsgBox reg.Address
End Sub

pglufkin
03-26-2013, 02:43 AM
Thank you, but I don't want to restrict this to column A. The cells which will become the range will be right under wherever my cursor is when the procedure starts. Thx again for your help.

pglufkin
03-26-2013, 03:19 PM
Thanks very much, I figured it out.