"wrong Data Type Error" Public Lookup Function

May 4, 2007

I have attached a file called Test2 which has a public function called DBLookup. The function looks in the attached access database simulating a Vlookup just like in Excel. The problem I am having is when that data appears on sheet1. I am getting #VALUE in the cell and the erroe states "a used value in the formula is of the wrong data type".

my

Dim adoCN As ADODB.Connection
Dim strSQL As String

Const DatabasePath As String = "C:Test2.mdb"

'Function argument descriptions
'LookupFieldName - the field you wish to search
'LookupValue - the value in LookupFieldName you're searching for
'ReturnField - the matching field containing the value you wish to return...

View 5 Replies


ADVERTISEMENT

Wrong Data Type Supplied To UDF Error

Aug 31, 2007

My colleague and I are writing a udf which uses a "match/ index" combination to return a value to a cell from a named range in another sheet. The cell returns returns the error "value used in the formula is of the wrong data type". When we break down the code into a function which refers directly to the relevant cells, and a sub which returns the value in a message box, it works correctly: here's the code for the function and test sub:

Function MRL(PropertyType, ReturnType, Location, Year2) ....

View 7 Replies View Related

Wrong Data Type Error In Simple Array Formula

Jun 30, 2013

I am trying to use FIND and an array formula to find the position of text in a range of cells (A2 and A3 in the example) which could be one of a number of options (C1:D1 here). But the array formula throws up the following error: "A value used in the formula is of the wrong data type". The simplest illustration of the problem is as follows. The formula in B2 is

Code:
{=FIND(($C$1:$D$1),A2)}
and $C$1:$D$1 contain REF and ATM respectively. [/CODE]
REF
ATM
203047 05AUG 08.55 OKEHAMPTON ATM
#VALUE!
CO-OP GROUP 380611 REF 191 7553375222 BCC
22

We see that B2 has a #VALUE! error - wrong data type. But for some reason B3 is ok returning 22!

View 9 Replies View Related

SUMIF - Value Used In Formula Is Of Wrong Data Type

Jul 27, 2012

I have a formula =SUM(IF($I$4:$I$302="A",$K$4:$K$302)) works fine.

I am using the same formula referencing a different column =SUM(IF($W$4:$W$302="A",$Y$4:$Y$302))

And I get the error : "A Value used in the formula is of the wrong data type"

View 2 Replies View Related

Lookup Function Error Mismatching Data & N/a Error

Apr 27, 2007

my lookup isnt returning the correct data- already tried sorting it doesnt work im pretty sure ive put in the correct formula

View 6 Replies View Related

Lookup Function Returns Type Mismatch?

Feb 23, 2014

I get a Type mismatch from this line:

x = Application.WorksheetFunction.Lookup(2, 1 / (Range("G7:P7") = "A"), Range("G7:P7"))

View 1 Replies View Related

Index / Match Lookup With Two Columns - Runtime Type 13 Error

Feb 14, 2014

I am building a timeclock, and am using a user form to allow people to sign in/out.

I have a punch in form that logs the inputed username and password (after being checked against my employee list), along with a count of their username on this sheet (as a count of how many times they have punched in) and a timestamp (column 4). These values are all pasted to the first blank row in my worksheet "PunchInTimes".

Then, I have a punch out button that logs these same values the same way, only on "PunchOutTimes". Then, the idea is to link the index number of the PunchOutTimes record and PunchInTimes record for any given user, so that when they punch out, a complete record is pasted (to the first blank row) in a separate worksheet called "Timesheets".

I have been able to paste the username and count to the "Timesheets" sheet, however as soon as I try to index/match the count and inputed username (on the punch out form), I get an error 13 type mismatch.

I'm trying to paste the corresponding punch in time to this punch out time, so ive used an index/match with two columns (username and count) found in "PunchInTimes", and try to return the corresponding 4th column value (punch in time). After pasting the "punch out only" values to the PunchOutTimes, i used a "With/End With" statement, and set wsc equal to my 'timesheets' worksheet at the beginning of my code. So the line where I get my error is below in bold:

[Code] ......

View 4 Replies View Related

Lookup Type Function Returning Multiple Values

May 23, 2007

I have attached a sample spreadsheet which describes my problem.

In C2 and C3 under the first business coalitions column, I have written in text what I would like to be displayed automatically with a formula. The trouble is that, as you can see, Abbott Laboratories is a member of 3 business coalitions. Therefore, a simple vlookup doesn't work because that would only return 1 result.

View 5 Replies View Related

Error '13' Type Mismatch In Function Code

Oct 6, 2006

while the code works fine by itself in the sample file, when inserted into my other file which contains another set of algorithms, it generates a run time error '13' type mismatch whenever the 'Hide' button is clicked.

this line of the following function: b = x / tpi

Function range(x)
tpi = 2 * 3.1415927
b = x / tpi
a = tpi * (b - Int(b))
If (a < 0) Then a = tpi + a
range = a
End Function

View 9 Replies View Related

Cell Type Constants Returns Wrong Order

Nov 28, 2007

I'd like to add items on a UserForm1 ComboBoxes in the correct order but I can't. That's because with the code below, in ComboBox6P1 the items are added with mixed order:

For Each thing In .Range("AC6", .Range("AC65536").End(xlUp)).SpecialCells(xlCellTypeConstants)
If Trim(ComboBox4P1.Text) = thing.Value Then
For Each aNew In .Range("AD6", .Range("AD65536").End(xlToRight)).SpecialCells(xlCellTypeConstants)
If aNew.Row = thing.Row Then
ComboBox6P1.AddItem aNew.Value
End If
Next
Exit For
End If
Next

I should add items in ComboBox6P1 in order -> AD6, AE6, AF6, AG6, AH6, the rest are empty cells. Instead of it adds AF6, AG6, AH6, AD6, AE6. When I change .SpecialCells(xlCellTypeConstants) to .SpecialCells(xlCellTypeVisible ) it adds it in the correct order but with another 200 emtpy cells in the ComboBox6P1. The format of the cells is General.

View 9 Replies View Related

Method Failed Error And Data Type

May 14, 2007

The error is:
Method 'Range' of object '_Global' failed
Line it fails on:

Set r = Range("myRange")

Sub LearnCells()
Dim r As Range
Dim n As Long
Set r = Range("myRange")
For n = 1 To r.Rows.Count
If r.Cells(n, 1) = r.Cells(n + 1, 1) Then
MsgBox "Duplicate data in " & r.Cells(n + 1, 1).Address
End If
Next n

End Sub
Questions:

1) 1st Dim statement, is this valid? I still get a little unsure- in the data type lists in the help file, the list file does not list things like Workbook, Worksheet Range.
2) Why is the error ocurring?

View 9 Replies View Related

Match Function In Vba Returning Error "type Mismatch"

Nov 30, 2007

I am trying to use a match function in VBA to return a value when a number of values in a row match a certain criteria (I have tried the Find approach on the Ozgrid help pages but it is not what I am after). My problem using a match function of course is that when there is no match the code returns a type mismatch error. I have tried to circumvent the error problem using an "On error resume next" but this then delivers a match for all rows. Anyone have any thoughts about how I can get around this problem?

Sub DataSum()
Dim strData As String
Dim i As Integer
i = 0
Sheets("Sheet1").Activate
Range("B4", Range("B4").End(xlDown).Offset(0, 0)).Select
For Each cell In Selection
If cell.Value = 0 Then
i = i + 1
Else
strData = Sheets("Sheet1").Range("$B$4").Offset(i, 0)...........................

View 8 Replies View Related

Scoping Function As Public - But Not Available As Worksheet Function

Sep 24, 2012

I have a user defined function in one VBA module that I'd like to call from another module, so I would normaly scope it as "Public".

However, as I don't want it to be available to Excel as a worksheet function, I would also normally scope it as "Private"

Is there a way to have a function that is available to other VBA modules in the same project, but not to Excel as a worksheet function?

View 5 Replies View Related

Display "Error - Data Must Contain A 1 Or 0" If Wrong Data Is Entered?

Oct 11, 2009

I have a lil project, was wondering how to work this. I have several rows of numbers, thing is, they can only contain either a "1" or a "0" (zero). If anything else is entered other than a "1" or "0", I'd like to have a statement below it saying "Error - data must contain a 1 or 0" - or something similar.
I tried using conditional formatting - not working well.

View 2 Replies View Related

Keep Getting Error With Public Variable

Jul 8, 2008

I have a number of userforms that all reference the same worksheet. I wanted to create a public variable for that worksheet so I don't have to keep referencing it in each userform/commandbuttons etc. So I inserted a module and placed this declaration.

Option Explicit
Public MySh As Worksheet
Set MySh = ActiveWorkbook.Sheets("sheetName")
And I referenced it in a UserForm commandbutton

Private Sub CommandButton2_Click()
MySh.Range("i4") = Me.ComboBox1
MySh.Range("i5") = Me.TextBox1
End Sub

View 9 Replies View Related

Type Mismatch Error Message Comparing Value To Cell Error "Type Mismatch"

Nov 4, 2006

I'm trying to write a Macro that, in the active sheet (which contains plenty of data), deletes rows according to several criteria, for example:

- if cell(i, ar1(j)) = ERROR, delete row i and shift 1 up
(ar1 is an array of column numbers)

- if cell(i, ar3(j)) = 0, delete row i and shift 1 up
(ar3 is another array of column numbers)

Etc.

The problem is that, when I run it, I get a "Type Mismatch" error message, and I don't understand why. Here is the

Sub Delete_invalid_rows()
Dim i%, j%
Dim Nr%, valid As Boolean, BYPdata As Boolean
Dim ar1, ar2, ar3, ar4 As Variant
Nr = 1379
ar1 = Array(11, 14, 19, 20, 22, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 64, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 104, 106, 107, 109, 112, 116, 126, 127, 128, 129, 131, 133, 134, 135, 136, 137, 138, 139, 140, 142, 143, 145)..............

View 6 Replies View Related

Determining Data Type Of Argument In Custom Function

May 29, 2007

In VBA, True takes the integer value of -1. However, in Excel, it is 1.

I am writing a custom function that does arithmetic on a value. However, due to above, if the value is True, my custom function produces a different result than if I wrote an Excel formula to do the same thing.

Is there some way to identify the data type of a value passed into a function? Currently my function looks like this:

' Return the valueToIncrement with its magnitude increased by PctToAdd
Public Function INCREMENTPCT(valueToIncrement As Variant, PctToAdd As Variant) As Variant

INCREMENTPCT = valueToIncrement * (1 + PctToAdd)

End Function

Ideally I would like to identify whether the type is Boolean and adjust the value so as to give the same result as an Excel formula would give.

View 8 Replies View Related

Public Variable Producing Error

Feb 10, 2007

I want to define a varible named MonthEnd that I will use in more than one project. In a normal example the variable would look like this:

Dim MonthEnd As String
MonthEnd = Format(Sheet1.Range("C3"), "MMYY")

The problem is that I will be using this more than one time so I figured I could define this a Public constant like

Public Const MontEnd As String = Format(Sheet1.Range("C3"), "MMYY")

View 3 Replies View Related

LOOKUP Returns Wrong Or Odd Value

Mar 27, 2007

I have a very basic spreadsheet to calculate golfer handicaps based upon a course index. For some reason, my "LOOKUP" formula is not retrieving the data from the cell (column) next to the value I am searching...?

View 9 Replies View Related

Lookup Function To Lookup For Data In Another Table

Jul 29, 2008

I am trying to use lookup function to lookup for data in another table (we call it table A). Unfortunately, whenever the code is not in the table A, Excel will return the data from the previous row.... is there any possible way to prevent this... in another word, if the code does not exist in the table A, I want Excel to return 0 or some other figures.

View 9 Replies View Related

Lookup - Formula Returns Wrong Value/sum

Jul 16, 2009

I am using this formula

View 9 Replies View Related

Boolean Type Mismatch Error - On Error Resume Next Doesn't Work?

Apr 1, 2013

OK, so I have a userform with some text boxes that I have specially formatted to accept only date values in the form of mm/dd/yy. By default they are blank. I have a check in one of my codes that looks like this

Code:
If DateBox vbNullString And DateValue(DateBox) > checkdate Then
M1 = "NEOPRENE" & Chr(13)
Else
M1 = "" & Chr(13)
End If

Where DateBox is this specially formatted TextBox and checkdate is a future date being checked against.So if DateBox has a value in it AND that value is greater than the date being checked against the returend string is Neoprene, otherwise it is blank.

Well the problem I have is when the first condition returns FALSE, i.e. when DateBox is empty, the DateValue half still gets evaluated and returns a type missmatch error or something like that because DateValue("") returns an error. I have line of code 8 times, one for Neoprene, squeegee, etc. So the name of the text boxes are each unique and I am using M1, M2, M3, etc.

For other reasons, use of "On Error Resume Next" doesn't work for this situation because it causes a result opposite to what I want to happen.

View 2 Replies View Related

Call Public Function From Class Module

May 25, 2006

I have written a public function inside a class module. Is there anyway I could call the public function in Excel? What is the exact syntax to do it?

View 5 Replies View Related

Lookup Formula Started Returning Wrong Letters

Jul 17, 2013

I am using the formula: LOOKUP(A1,{"S","M","L","XL"},{"S","M","L","XL"}) on a cell containing: EF-2147.(S) so that it will return a S [or M, L etc. if it were .(M),.(L)] but it just keeps returning #N/A. I tried putting in "(S)" etc. in the lookup formula but it then started returning the wrong letters.

View 2 Replies View Related

Error If I Enter Wrong Criteria

Oct 27, 2008

The following code works like a dream for me, but if was to enter the wrong letter, not "N" or "R" and i tried to delete it, a debug message appears?

Is there a way to allow any letters to be deleted?

Here is my code

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 17 Then
With Range("C" & Target.Row & ":R" & Target.Row).Interior
Select Case Target.Value
Case "R": .Color = RGB(184, 204, 228)
Case "N": .Color = RGB(120, 120, 120)
Case Else: .Color = RGB(255, 255, 255)
End Select
End With
With Target.Font
Select Case Target.Value
Case "R": .Color = RGB(184, 204, 228)
Case "N": .Color = RGB(120, 120, 120)
Case Else: .Color = RGB(0, 0, 0)
End Select
End With
End If
End Sub

View 9 Replies View Related

IRR Function Is Returning The Wrong Value

Nov 7, 2008

I'm trying to figure out an Internal Rate of Return for a spreadsheet. The answer is supposed to be: 29.42% however I'm getting 25.94%. Does anyone know what I'm doing wrong in my IRR function on the Profitability worksheet? I'm currently using Excel 2007 by the way.

View 4 Replies View Related

Mod Function Works Wrong

Dec 28, 2006

I was trying to explain modulus to someone and they wanted to know why you can "flip" symbols mod(-6,7) = 1 in Excel. So I got to explaining that -6 Mod 7 is the same as -6-(|-6/7|)*7 which is how you get 1.

And that's when I realized... |-6/7| = 0 not -1. Then I looked in VBA and sure enough -6 mod 7 = -6. Apparently the problem boils down to the Integer conversion. Excel is performing the integer coversion by rounding down (INT) wheras VBA appears to be using CINT.

So here is how it work out in excel:
-6-(|-6/7|)*7
-6-(|-0.857142857|)*7
-6-(-1)*7
-6--7
-6+7=1

But in VBA you get
-6-(|-6/7|)*7
-6-(|-0.857142857|)*7
-6-(0)*7
-6-0=-6

View 9 Replies View Related

Match Function Given Wrong Position

May 14, 2009

I have the following equation programed in Excel, (see file attached). I do not understand while the match funstion is not working the lookup value is the on in cell N1 the array is from B1:F1. The return value should be 3 but I get #NA instead at the begining I was thinking that the values were different but then I compared cell =D1=N1 and the result was TRUE, meaning that they are equal

View 4 Replies View Related

Wrong DataType Parsed Into Function

Jul 28, 2013

I have a function that starts as follows:

Function Timings(StartTime As Double, EndTime As Double, Times As Range, Calc As Long)

StartTime will refer to a cell in Column A that holds a date and time EndTime will refer to a cell in Column B that holds a date and time Times is the range of cells that hold times of the day I am testing against. The cells are within a range defined called Hours. Calc refers to different criteria that I am testing again. This is a number list between 1 to 5.

The function works well if the cell that StartTime or EndTime refer to cell values that are date/time. If the data is anything different, I get a #VALUE error such as if the cell contents is text. I tried to trap the error to see if the data inputted in the cell is not date/time and thus cannot be converted to a Double but it always throughs up #VALUE and the function seems as though it fails when it . Is there anyway to trap the error of wrong data type in the first the first few lines of code in the function?

Example

Column A Column B Column C Formula
05/01/2013 12:00 06/01/2013 09:00 =Timings(A1,B1,Hours, 1)
25/02/2013 15:00 30/02/2013 14:30 =Timings(A2,B2,Hours, 1)
03/01/2013 16:00 abc =Timings(A3,B3,Hours, 1)

Row 2 will return #VALUE becuase 30/02/2013 14:30 is an invalid date (30th Feb does not exist so Excel seems to pickup as text)

Row 3 will return #VALUE because it is text and cannot be converted to a double data type

View 9 Replies View Related

Look Up Function Is Coming Up With The Wrong Results On Several Items

Oct 16, 2009

The attached workbook contains a cell with validation list selection and a look up function. The validation list selection works fine, but the look up function is coming up with the wrong results on several items. Is this a bug or am I doing something wrong?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved