MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 15th, 2002, 10:31 PM   #1
KeithGrindle
New Member
 
Join Date: Apr 2002
Posts: 5
Default

I am getting a type mismatch error when running this code. It goes to the input box and then after a number is entered into the input box I get a type mismatch error. Any help would be appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrorHandler

Dim Width As Double
Dim Height As Double
Dim Cellnum As Integer
Dim myrange As Range



If Not Intersect(ActiveCell, Range("WallA")) Is Nothing Then

If ActiveCell.Text = "HWT" Or ActiveCell.Text = "HWA" Then
Width = Application.InputBox("Please enter the width for this HVAC Window", "HVAC Window Width", Type:=1)
Cellnum = ActiveCell.Range("WallA").Rows - 60
Worksheets("Formulas").Range("ValuesWallA").Row(Cellnum).Value = Width

Else

If ActiveCell.Text = "CW" Then

Width = Application.InputBox("Please enter the width for this Custom Window", "Custom Window Width", Type:=1)
Cellnum = ActiveCell.Range("WallA").Rows - 60
Worksheets("Formulas").Range("ValuesWallA").Row(Cellnum).Value = Width
Height = Application.InputBox("Please enter the width for this Custom Window", "Custom Window Height", Type:=1)
Cellnum = ActiveCell.Range("WallA").Rows - 60
Worksheets("Formulas").Range("WallAWinandDrHeight").Row(Cellnum).Value = Height

Else

If ActiveCell.Text = "CF" Then

Width = Application.InputBox("Please enter the width for this Custom Fill Panel", "Custom Fill Width", Type:=1)
Cellnum = ActiveCell.Range("WallA").Rows - 60
Worksheets("Formulas").Range("ValuesWallA").Rows(Cellnum).Value = Width
Height = Application.InputBox("Please enter the width for this Custom Fill Panel", "Custom Fill Height", Type:=1)
Cellnum = ActiveCell.Range("WallA").Rows - 60
Worksheets("Formulas").Range("WallAWinandDrHeight").Row(Cellnum).Value = Height
Else

If ActiveCell.Text <> "HWA" Or ActiveCell.Text <> "HWT" Or ActiveCell.Text <> "CW" Or ActiveCell.Value <> "CF" Then

Cellnum = ActiveCell.Range("WallA").Rows - 60
Worksheets("Formulas").Range("ValuesWallA").Row(Cellnum).Formula = "=VLOOKUP(DN(cellnum),PartsList,3,FALSE)"


End If

End If
End If
End If
End If

Exit Sub
ErrorHandler: MsgBox "Error number: " & Err.Number & vbCrLf & vbCrLf & Err.Description

End Sub





Thanks,

Keith
KeithGrindle is offline   Reply With Quote
Old May 16th, 2002, 01:01 AM   #2
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi
At a glance your code looks fine...
You are, however, using words, namely, "Width" and "Height", which VBA uses for property assignments for many different objects.
I would change the name of these variables to start.
If that does not solve your problem then we'll take it from there.
Tom
Tom Schreiner is offline   Reply With Quote
Old May 16th, 2002, 01:04 AM   #3
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Your statement:
'
'

ActiveCell.Range("WallA").Rows - 60

'
'
Is returning a Range Object and NOT an Integer....should change this to;
'
'

ActiveCell.Range("WallA").Rows.Count - 60




_________________
Kind Regards,
Ivan F Moala
Have a Nice day

[ This Message was edited by: Ivan F Moala on 2002-05-16 00:11 ]
Ivan F Moala is offline   Reply With Quote
Old May 16th, 2002, 01:07 AM   #4
Brian
Board Regular
 
Join Date: Apr 2002
Posts: 113
Default

1) I tried the input box alone and it worked fine. no data mismatch there.

Sub try()
Dim Width As Double
Width = Application.InputBox("Please enter the width for this HVAC Window", "HVAC Window Width", Type:=1)
MsgBox "width = " & Width
End Sub

2) Your next line:

Cellnum = ActiveCell.Range("WallA").Rows - 60

is a bit perplexing to me because "ActiveCell" is by definition only one cell so ActiveCell.rows must always equal 1. I don't understand how the range fits in there. I presume that perhaps you want to know where the ActiveCell is within the Range("WallA") If yes, then you could use Range("WallA").row - ActiveCell.row.

3) When I name a range "TestRange" and select a cell in that range, then the following code gives a "type mismatch" error. I suspect that this is your problem.

'Option Explicit
Sub test2()
Dim Cellnum As Integer
Cellnum = ActiveCell.Range("RangeTest").Rows
MsgBox "Cellnum = " & Cellnum
End Sub

When i commented out the Dim statement and opened the "locals" window, Cellnum turned out to be a variable other than an integer, indicating that the formula does not return an integer.

4) Suggestion: For debugging, comment out your error handler so that the normal VBA error message can bring you directly to the incorrect line.

PS: From excel help:

Be careful to distinguish between the active cell and the selection. The active cell is a single cell inside the current selection. The selection may contain more than one cell, but only one is the active cell.
Brian is offline   Reply With Quote
Old May 16th, 2002, 01:11 AM   #5
Brian
Board Regular
 
Join Date: Apr 2002
Posts: 113
Default

Ivan,

You beat me to it, but I get a "Invalid Qualifier" error that highlights "row" in your code.
Brian is offline   Reply With Quote
Old May 16th, 2002, 01:19 AM   #6
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-05-16 00:11, Brian wrote:
Ivan,

You beat me to it, but I get a "Invalid Qualifier" error that highlights "row" in your code.
Hi Brian....one of the things about this board is that while you a busy with answering one Question, so are others and you
usually get caught ie you finish the Q then post and find someone else has answered JUST
before you .......you are correct on this
point BUT if you look again you will find
that I utilised the Boards Edit function and
changed the code .....thanks for that.


__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Old May 16th, 2002, 07:28 AM   #7
KeithGrindle
New Member
 
Join Date: Apr 2002
Posts: 5
Default

I've changed Width and Height to be Wid an Hght so that should help.

The line:
Cellnum = ActiveCell.Range("WallA").Rows - 60
was set to - 60 because for some reason cell numb was returning 61 when this code was running. What I want is whatever position the activecell is then I want to put the value of wid or height in that same position in either the range("ValuesWallA") or range("WallAWinandDRHeight") depending on whether the input is wid or hght.

I change the line to Cellnum = ActiveCell.Range("WallA").Rows.Count and I am now getting a runtime error 451: Property let procedure not defined and property get procedure did not return an object. It points
to this line: Worksheets("Formulas").Range("ValuesWallA").Row(Cellnum).Value = Wid

If I change it to rows(cellnum) then the input box will not go away. I am thinking that maybe it is looking for a range object but I am not to sure. Any help would be greatly appreciated.

Thanks for the previous help and thanks in advance for any future help on this.

Keith
KeithGrindle is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:20 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes