LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Problems with WorksheetFunction.Match

Beautiful. That did exactly what I needed. I'm in the process of converting
a massive, time-consuming workbook into a smaller, more efficient one using
VBA instead of the numerous and lengthy Excel formulas currently in use. I
knew I had to get past this because I have several more instances where I'm
going to need to use code very similar to this.

Thanks for the help and insight.

"Patrick Molloy" wrote:

this line will raise issues for you since cells refers tot he active sheet,
not necessarily Employoyees. A fix is to use the WITH statement

TotalEEs = Application.WorksheetFunction.CountIf(Worksheets
_("Employees").Range(Cells(3, 1), Cells(LastEERow, 1)), ClientNum)

WITH Worksheets("Employees")
TotalEEs = Application.WorksheetFunction.CountIf(.Range(.Cell s(3,
1), .Cells(LastEERow, 1)), ClientNum)
END WITH
!!!note the . before cells, so they're also part of the WITH worksheet

the same is true for AllClients

WITH Worksheets("Employees")
AllClients = .Range(.Cells(3, 1), .Cells(LastEERow, 1))
END WITH







"Luke" wrote:

I just changed the Range from dynamic (using Cells) to static ("A3:A27745")
and it took it, but I need it to be dynamic as the number of rows will change
monthly. However, once it got past the Range problem, it hit another one at
the "TotalEEs = " line, so I've got that to look forward to as well.

"Patrick Molloy" wrote:

teh MATCH function raises an error when no match is found, I prefer to wrap
it in my own to trap the error, others prefer ON ERROR RESUME NEXT


AllClients = Worksheets("Employees").Range(Cells(3, 1), Cells(LastEERow, 1))
should be
SET AllClients = Worksheets("Employees").Range(Cells(3, 1),
Cells(LastEERow, 1))

have you stepped to this line and evaluated the various varaibles, eg what
does ClientNum contain? select the sheet Employees then in the immedaite
window put Allclients.select to ensure that the range is good.

make sure you have
OPTION EXPLICIT at the start of the module


"Luke" wrote:

The more I work with it, the more it appears the problem starts at the
"AllClients =" line. There's something about the way I typed the range that
it doesn't like. I even tried getting rid of that line and just putting the
range directly into Match, but it didn't like that either.

Oh, and sorry about the way the code looks. I copied and pasted it directly
from the editor and that's how it came out.

"Luke" wrote:

I'm really just wanting to know WHY this doesn't work, although solutions are
always welcome. Here is the code:

Private Sub ComboBox1_Change()

Dim MaxEEs As Long, LastEERow As Long, TotalEEs As Long, ClientStart As Long
Dim ClientNum As Integer, EEList As Long, AllClients As Range

MaxEEs = Worksheets("Employees").Range("P1")
LastEERow = MaxEEs + 2
With UserForm2.ComboBox2
.AddItem ("All Employees")
If UserForm2.ComboBox1.ListIndex = 0 Then
TotalEEs = MaxEEs
ClientStart = 1
End If
ClientNum = Val(Left(UserForm2.ComboBox1.Value, 4))
AllClients = Worksheets("Employees").Range(Cells(3, 1),
Cells(LastEERow, 1))
ClientStart = Application.WorksheetFunction.Match(ClientNum,
AllClients, 0)
TotalEEs = Application.WorksheetFunction.CountIf(Worksheets
_("Employees").Range(Cells(3, 1), Cells(LastEERow, 1)), ClientNum)
For EEList = ClientStart To TotalEEs
.AddItem (Worksheets("Employees").Range("A2").Offset(EEList , 2))
Next EEList
End With
End Sub

Whenever you select a company from combo box 1, this is supposed to fill
combo box 2 with all of the selected company's employees. 100% of the time,
the number of the selected client (ClientNum) WILL be found on the
"Employees" sheet. But every time I run it, it gets to the
WorksheetFunction.Match line and gives me this: "Application-defined or
object-defined error".

As I mentioned, I'm really wanting to know why this doesn't work, so I can
avoid doing it in the future. But any code corrections are also appreciated.

Thanks.



 
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
worksheetfunction.match Li Jianyong[_2_] Excel Programming 11 March 10th 10 10:07 PM
Problems with WorksheetFunction.Index and WorksheetFunction.Match Luke Excel Programming 4 October 14th 09 12:57 AM
Problems with application.worksheetfunction.correl TFriis Excel Programming 3 November 19th 07 08:20 AM
worksheetfunction.match David Robinson[_3_] Excel Programming 4 November 15th 03 06:35 PM
Worksheetfunction MATCH Yves Janssens Excel Programming 2 October 6th 03 03:25 PM


All times are GMT +1. The time now is 02:55 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"