Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

INDEX & MATCH   Help with syntax please...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
u473 - 25 May 2008 01:49 GMT
I am using Interior.ColorIndex in Sheet1 to define Work Hours per day,
8, 9, 10...
and Font.ColorIndex to define Week Worked days, 5, 6  or 7
which in turn with a Select Case allows me to call the applicable Rate
Code in Sheet3.
It works well until I try to retrieve with INDEX & MATCH the Row/Colum
intersect value of Position and Rate to assign it to my variable Cost.
Finally, I want to store in Sheet2 the product of Force & Cost, in the
same relative cell position  i,J of Sheet1
----------------------------------
Sub Test()
Dim ws1 As Worksheet: Dim ws2 As Worksheet: Dim ws3 As Worksheet
Dim LastRow As Long: Dim LastCol As Long: Dim i As Long, Z As Long
Dim rng1 As Range: Dim rng2 As Range: Dim rng3 As Range: Dim rngfound
As Range
Dim iClr, fClr, Force, Cost  As Integer: Dim Position, Rate As String
Dim Table, Empl, Rates As Range
     Set ws1 = Worksheets("Sheet1")
     LastRow = ws1.Cells(Rows.Count, "A").End(xlUp).Row
     LastCol = ws1.Cells(1, Columns.Count).End(xlToLeft).Column
     Set ws2 = Worksheets("Sheet2"):   Set ws3 = Worksheets("Sheet3")
     Z = 2
     'Application.ScreenUpdating = False
     For i = 2 To LastRow
         For J = 2 To LastCol
              iClr = ws1.Cells(i, J).Interior.ColorIndex
              fClr = ws1.Cells(i, J).Font.ColorIndex
               Force = ws1.Cells(i, J).Value
          Position = ws1.Cells(i, 1).Value
          Select Case iClr
              Case 40
              If fClr = -4105 Then
                   Rate = "509"
              ElseIf fClr = 5 Then
                   Rate = "609"
              Else
                   Rate = "709"
              End If
              Case 36
               ...............
        End Select
Error here in Index & Match
   in trying to assign to Cost, the value of the Row/Column
intersect
   I guess my problem is in the 2 following lines.
   I tried using named ranges but sill could not pass that hurdle.
Cost =INDEX(Sheet3!A1:P4,MATCH(Position,Sheet3!A:A,
0),MATCH(Rate,Sheet3!1:1,0))
              ws2.Range(i,J).value = Force* Cost
         Next J
     Next i
     Application.CutCopyMode = False
End Sub

Thank you for your help,
Celeste
Ken Johnson - 25 May 2008 07:16 GMT
> I am using Interior.ColorIndex in Sheet1 to define Work Hours per day,
> 8, 9, 10...
[quoted text clipped - 52 lines]
> Thank you for your help,
> Celeste

INDEX and MATCH are WorksheetFunctions. I think the syntax for the
formula for Cost should be...

WorksheetFunction.Index(Sheet3.Range("A1:P4"),
WorksheetFunction.Match(Position, Sheet3.Range("A:A"), 0),
WorksheetFunction.Match(Rate, Sheet3.Range("1:1"), 0))

Also...

> Dim iClr, fClr, Force, Cost  As Integer: Dim Position, Rate As String
> Dim Table, Empl, Rates As Range

dimensions iClr, fClr, Force, Position, Table and Empl as Variant. Is
that your intention? If not then maybe it should be...

Dim iClr As Integer, fClr As Integer, Force As Integer, Cost  As
Integer: Dim etc

Ken Johnson
u473 - 25 May 2008 13:36 GMT
Thank you for your answer.
I copied your WorksheetFunction syntax and corrected my Dim's
I get the following error on the same line
Runtime error '1004'. Unable to get the Match property of the
WorksheetFunction class.
I am using Excel 2003. Any suggestion ?
Thank you again,
Celeste
Ken Johnson - 25 May 2008 13:57 GMT
> Thank you for your answer.
> I copied your WorksheetFunction syntax and corrected my Dim's
[quoted text clipped - 4 lines]
> Thank you again,
> Celeste

What are the values of Position and Rate when the error occurs?
You will get that error message when either the Position value can't
be found in column A or the Rate value can't be found in Row 1.

Ken Johnson
u473 - 25 May 2008 14:15 GMT
Additional research in Debug mode with watches to test each section of
that long code line.

Tst1 = WorksheetFunction.Match(Position, Sheet3.Range("A:A"), 0)
Tst2 = WorksheetFunction.Match(Rate, Sheet3.Range("1:1"), 0)

Tst1 gets populated fine but Tst2 gets the error 'Unable to get the
Match property
of the WorksheetFunction class'
My headers in each cell of Row 1 for Code Rates look like 508, 509,
510 are Text not Integers
and my Select Case populates the Rate to be searched with a string.
I cannot detect what caused the error in Tst2.
Ken Johnson - 25 May 2008 14:28 GMT
> Additional research in Debug mode with watches to test each section of
> that long code line.
[quoted text clipped - 9 lines]
> and my Select Case populates the Rate to be searched with a string.
>  I cannot detect what caused the error in Tst2.

So Rate is text and so are the row one values being looked up.
When the error occurs and you click the debug button, what do you see
when you hover the cursor over Rate, its error causing value should
appear in a little pale yellow box.

Ken Johnson
u473 - 25 May 2008 15:44 GMT
On the first pass, Position = "Manager  for Row 2   and      Rate =
"508" from B2 as expected.
Tst1 = 2 which is the expected value
but hovering over Tst2 = 0  and I should expect 2 also.
I checked variables and Headers names, and I have no leading blanks in
my Rate variable nor in my headers names.
Thank you for your time,
Celeste
Ken Johnson - 26 May 2008 01:34 GMT
> On the first pass, Position = "Manager  for Row 2   and      Rate =
> "508" from B2 as expected.
[quoted text clipped - 4 lines]
> Thank you for your time,
> Celeste

If it is at all possible to email me the workbook for me to have a
close look, feel free to send it (kencjohnson is my gmail (gmail.com)
account) name)

Ken Johnson
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.