LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default New to Programming

The H1 in

...WorksheetFunction.Match(H1,Worksheets("NAMES"). Range("A10:K10"), 1))...


looks wrong too, if you mean cell H1 (in which worksheet?). You would
need
to replace it by Worksheets("whatever").Range("H1").

For debugging stuff like this, it can help to split up the complicated
expressions, e.g.:
(BTW, for brevity you can omit "WorksheetFunction)

dim m1 as long, m2 as long
m1 = Application.Match(Worksheets("INPUT").Cells(row, D).Value, _
Worksheets("NAMES").Range("A10:A100"), 1)
m2 = Application.Match(H1,Worksheets("NAMES").Range("A1 0:K10"), 1)
ML = _
Application.Index(Worksheets("NAMES").Range("A10:K 100"),m1, m2) _
* Cells(row, "H")

It's then clearer which Match is causing the problem (I suspect the
second one, because of the "H1")

You could also make things clearer by using variables for the
Worksheets:

Dim wsNames as Worksheet, wsInput as Worksheet

set wsNames = Workheets("NAMES")
set wsInput = Workheets("Input")
'' and then
m1 = Application.Match(wsInput.Cells(row, D).Value,
wsNames.Range("A10:A100"), 1)
'' etc...


(BTW I'm sure this could all be done with just worksheet functions. It
feels as if you're overcomplicating things a lot.)

Andrew


Anice wrote:

I made those changes, that was actually a typo that I left off the quotations
around the q. I'm still getting an error that says "Unable to get the Match
Property of the WorksheetFunction class" Any more tips??

Thank you again for everything!

"Andrew Taylor" wrote:

I suspect that instead of
Application.WorksheetFunction.Match(Worksheets("IN PUT").Cells(row, D).Value,

you should have
Application.WorksheetFunction.Match(Worksheets("IN PUT").Cells(row, "D").Value,


The first version tries to variable called D, and as it's unset, it's
an invalid
parameter to the Cells method.

As a general point, I'd strongly recommend that you use Option Explicit
for all your macros (set on "Require Variable Declaration" in VBA
Tools/Options). This would have caught the error by telling you that
D was undefined.

I'm also unsure what the line
ActiveCell.Formula = ActiveCell.Formula + ML

is supposed to do: maybe you mean
ActiveCell.Value = ActiveCell.Value + ML




hth
Andrew Taylor




Anice wrote:
I am new to programming in VBA, and I am having trouble getting my program to
do what I want it too. Basically, We enter names and hours worked into one
sheet, then I want to find that persons hourly rate from another worksheet
and multiply it by their hours. These totals need to be added together to
only include employees of the company and not contractors, material, or
travel (that is what the "M" stands for). I am getting runtime errors when I
run the program. Any help, suggestions or otherwise is greatly appreciated!!

Function Labor()
Dim row As Long
ActiveCell.Formula = 0
For row = 3 To 34
If Worksheets("INPUT").Cells(row, "C").Value = "M" Then
ML =
Application.WorksheetFunction.Index(Worksheets("NA MES").Range("A10:K100"),
Application.WorksheetFunction.Match(Worksheets("IN PUT").Cells(row, D).Value,
Worksheets("NAMES").Range("A10:A100"), 1), WorksheetFunction.Match(H1,
Worksheets("NAMES").Range("A10:K10"), 1)) * Cells(row, "H")
ActiveCell.Formula = ActiveCell.Formula + ML
End If
Next row
End Function

Thank you!!




 
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
VBA Programming [email protected] New Users to Excel 2 May 28th 08 08:38 PM
CD Programming nelson Excel Discussion (Misc queries) 0 June 4th 06 04:32 PM
VBA programming kush28 Excel Programming 1 February 9th 06 08:05 AM
programming Daren Excel Programming 1 November 10th 05 09:55 PM
Please help with programming RandyJ Excel Programming 2 October 8th 04 10:59 PM


All times are GMT +1. The time now is 12:04 PM.

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"