View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Andrew Taylor Andrew Taylor is offline
external usenet poster
 
Posts: 225
Default New to Programming

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!!