Named Range Manipulation

lee2smooth03

New Member
Joined
Nov 13, 2011
Messages
20
Hello all,

my worksheet has a named range that it constantly being resized; every week there's a new row added, etc. My goal is to traverse the array from top to bottom with checks at each row (VBA of course).

An IF statement should check to see if CONDITION is met at each row. If it is, then the row should be searched for a value. This looks and sounds an awful lot like the VLOOKUP function, but the difference is that in VLOOKUP, the user knows which column to search because it asks for an offset value. Furthermore, I'm trying to avoid the use of "APPLICATION.WORKSHEET" functions since they begin to look cumbersome.

There is a method (or property) called Rows.Find that asks for lots of inputs, but I'm not to keen on how to satisfy it's requirements. After inputting the value that I'm looking for, the rest of the inputs seem helpful, but ambiguous.

So here's what I need to know:
  • How can I turn each row of a named range into an array to be traversed/searched?
  • How to use the .FIND method for rows; Excel 2010's example wasn't very helpful
  • How to advance the last row of my named range to the next row using array properties of the range and offset the method/property...

In the Rows.Find example, could you please include the LookIn and LookAt inputs so that I can get a sense of how to assign these values. Any help would be great; hopefully I'm not far off from any of the answers received. Below are snippets of code to demonstrate my progress (or lack there of)

Rich (BB code):

    Select Case combText(theData.Cells(rowCount, 1), thisDay)    'combText is a function that compares strings
        Case -1, 1                                              'these two values indicate "No Match" 
            counter = counter + 1                               'counting the mismatches
        Case 0
            'subData was declared as an array at the beginning of the funciton
            'every time the loop is run, subset is supposed to become the row that had matching string values
            'the program doesn't seem to have a problem with subData, but it seems redundant 
            Set subData = theData.Range(theData.Cells(rowCount, 1), theData.Cells(rowCount, 1).End(xlRight))
            
            theData.Cells(rowCount, 1).Interior.Color = RGB(100, 200, 150)  'verifies the function test
            counter = theData.Columns.Count                                 'more verification
            'at this point I'd like to assign some variable to be the number of columns in theData
            'there is supposed to be a loop that traverses this row to search for the item
            theData.Rows.Find(item, after:=theData.Cells(rowCount,1),lookin:= xlValues,lookat:= xlWhole,searchorder:= xlByColumns)
            
            
    End Select
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hey,

after posting in this thread, the loop began working, but the conditional statement is not very effective. Follow me
if you think you can help.

This thread is still very much alive; I'm still very interested in responses to help optimize this process.

Thanks!:)
 
Upvote 0
If you're worried about application.workheetfunction looking cumbersome, you could do the following

Code:
set fn = application.worksheetfunction

then use fn in place of the full code
Code:
mySum = fn.sum(range("A1:A100"))

for instance.
 
Upvote 0
Thanks Weaver,

that's good advice that I'll put to good use in the future. In the case of using embedded worksheet functions, would I have to call the "fn" variable in front of every function called or does calling it once suffice for everything within the parentheses?

Ex:
  • application.worksheet.sumif(application.worksheet.function.left("hi mom",2), h)
  • application.worksheet.sumif(left("hi mom",2),h)
 
Upvote 0
In front of every one, although you could possibly use 'with'

Code:
with fn
    myResult.sumif(.left("hi mom",2), h))
end with
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,938
Members
449,197
Latest member
k_bs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top