Thread: Finding Ranges
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JLong JLong is offline
external usenet poster
 
Posts: 1
Default Finding Ranges

Hi, I having a problem finding the appropiate way of
selecting ranges. I have a group of workbooks with a
table on a sheet. These tables varie in size (rows &
column numbers). I need to open each workbook and find a
value on the first column and then retrieve the
corresponding value on the last column. I am trying to
create a VBA macro to do this. Here is whare I am stuck.

Dim Wsheet As Worksheet
Dim Rag As Range
Dim Urag As Range
Dim str As Variant
Dim StC As String
Dim I As Integer
Dim UpL As String
Dim MyRag As String
Dim ID as String

ID = "AK-0252"

Set Wsheet = ThisWorkbook.ActiveSheet

Set Urag = Wsheet.UsedRange

str = Split(Urag.Address, "$")

For I = 0 To UBound(str)
If str(I) < "" Then
StC = StC & str(I)
End If
Next I

UpL = Mid(StC, InStr(1, StC, ":") + 2, Len(StC))

MyRag = "A1:A" & UpL


Wsheet.Range(MyRag).Select

Selection.Find(What:=ID, After:=ActiveCell,
LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, MatchCase _
:=False).Activate

Set Rag = Application.ActiveCell

Rag.Select

Up to here I am doing what I want, but I am not sure this
is the most efficient way. Can someone give me an idea of
how to do this better? TIA