Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Set range, perform operation, set new range, repeat

Excel 2003/2007, using VBA:

I got this working to find the text "MatchText" in the I column of the
worksheet "SheetName", go down 2 cells, and create a range from that cell to
the last used cell in column I:

Set TempRange = Worksheets("SheetName").Range("I" &
Application.Match("MatchText", Worksheets("SheetName").Range("I:I"), 0) + 2,
Worksheets("SheetName").Range("I65536").End(xlUp))

I've been trying to use modifications of this to do the following, but
nothing works.

1) How can I set a range by:
a) Find the first occurence of a specific (string) value in Column D
b) From that found match, find a match for a different string below but in
Column B, and START the range there
c) From my Range start, go to column AA and find the first blank cell in
that column and down from my StartRange row.

Example: 1st string to match = "1stString"
2nd string to match = "2ndString"

So in column D I find the first occurrence of "1stString" in D22. Now,
underneath that match and in column
B I need to find 1st occurrence of "2ndString". I find that in B26. So my
range begins at B26.
Now, in column AA I need to find the 1st blank cell after row 26 (where my
range has started)
The first blank cell after row 26 and in column AA is AA36.
So, my range is Range(B26:AA36). Then I do some VLookups/Index/Match based
on values in this range and on other sheets, then when I'm done, and
starting at D37 (because the last row in my previous range was 36), I look
for "1stString" again, and it all repeats until there are no longer
occurrences of "1stString" in D.

Can someone help me figure out how to do this "Set range based on found
values and other found values, etc."? I appreciate any help, and thanks for
reading.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Set range, perform operation, set new range, repeat

Hi

First, I will rewrite your original code, using a With statement and
second I will use .Find to search for the string, see below:

1)
With Worksheets("SheetName")
Set temprange1 = .Range("I" &
Application.Match("MatchText", .Range("I:I"), 0) +
2, .Range("I65536").End(xlUp))
End With

2)
With Worksheets("SheetName")
Set temprange2 = .Range(.Range("I:I").Find(what:="MatchText",
After:=.Range("I1"), _
lookat:=xlWhole).Offset(2), .Range("I" &
Rows.Count).End(xlUp))
End With

With theese techniques in memory, the code below should do what your
need:

Sub ddd()
Dim TempRange As Range
Dim aaRow As Long

With Worksheets("SheetName")
Set f = .Range("D:D").Find(What:="1stString", After:=.Range("D1"),
LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:= _
True, SearchFormat:=False)
Set fFound = f
Do
If Not f Is Nothing Then
Set f1 = .Range(f.Offset(0, -2), .Range("B" &
Rows.Count).End(xlUp)) _
.Find(What:="2ndString", After:=f.Offset(0, -2),
LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:= _
True, SearchFormat:=False)

Set TempRange = Range(f1, .Range("AA" &
f.Row).End(xlDown).Offset(1, 0))
aaRow = TempRange.Row + TempRange.Rows.Count - 1
End If
'Here goes your Vlookups etc.

Set f = .Range("D:D").Find(What:="1stString",
After:=.Range("D" & aaRow))

Loop Until f.Address = fFound.Address
End With

End Sub

Regards,
Per

On 11 Okt., 15:44, "CompleteNewb" wrote:
Excel 2003/2007, using VBA:

I got this working to find the text "MatchText" in the I column of the
worksheet "SheetName", go down 2 cells, and create a range from that cell to
the last used cell in column I:

Set TempRange = Worksheets("SheetName").Range("I" &
Application.Match("MatchText", Worksheets("SheetName").Range("I:I"), 0) + 2,
Worksheets("SheetName").Range("I65536").End(xlUp))

I've been trying to use modifications of this to do the following, but
nothing works.

1) *How can I set a range by:
a) Find the first occurence of a specific (string) value in Column D
b) From that found match, find a match for a different string below but in
Column B, and START the range there
c) From my Range start, go to column AA and find the first blank cell in
that column and down from my StartRange row.

Example: *1st string to match = "1stString"
2nd string to match = "2ndString"

So in column D I find the first occurrence of "1stString" in D22. *Now,
underneath that match and in column
B I need to find 1st occurrence of "2ndString". *I find that in B26. *So my
range begins at B26.
Now, in column AA I need to find the 1st blank cell after row 26 (where my
range has started)
The first blank cell after row 26 and in column AA is AA36.
So, my range is Range(B26:AA36). *Then I do some VLookups/Index/Match based
on values in this range and on other sheets, then when I'm done, and
starting at D37 (because the last row in my previous range was 36), I look
for "1stString" again, and it all repeats until there are no longer
occurrences of "1stString" in D.

Can someone help me figure out how to do this "Set range based on found
values and other found values, etc."? *I appreciate any help, and thanks for
reading.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a function to perform this operation? Ayo Excel Discussion (Misc queries) 2 July 17th 09 03:17 AM
Cant perform operation since the project is protected PaulSimonGB Excel Programming 0 January 25th 09 11:57 PM
Can't perform requested operation in excel macro John[_19_] Excel Programming 2 March 12th 08 03:54 AM
Connection Cannot Be Used to Perform this Operation alexcn Excel Programming 0 May 8th 07 07:13 PM
Complex Macro to perform an operation as it steps down cells? Jeni Q Excel Worksheet Functions 0 August 25th 05 04:38 PM


All times are GMT +1. The time now is 03:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"