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, 12:00 AM   #1
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

When a user clicks a command button how would I write code that will check the number the user entered into a textbox to the same number in cells A8:A93 and then insert the value the user entered into another textbox in column D of that row?

TsTom, First thanks for all your help so far. I'm trying a different way to get what you've been helping me with. It's just to hard to explain what I'm trying to do with out you seeing my workbook. So, I figure if I can compare the two numbers then I can hopefully get it to do the other part as well.

thanks,

__________________
I appreciate the help from everyone at Mr. Excel.

viper
viper is offline   Reply With Quote
Old May 15th, 2002, 12:21 AM   #2
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi Vip.
I gotta run...
Textbox1 is the number to search
Textbox2's value or text will be placed
in Column D on the same row...



Private Sub CommandButton1_Click()
Dim c
For Each c In Range("A8:A93")
Debug.Print c.Value
If c.Value = Val(TextBox1) Then
Cells(c.Row, 4) = TextBox2
Exit For
End If
Next
End Sub


Tom
Tom Schreiner is offline   Reply With Quote
Old May 15th, 2002, 12:34 AM   #3
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Hi viper,

If you need to show the value of textbox2,
please try this.


Private Sub TextBox1_Change()
Dim ret
ret = Application.Match(Val(TextBox1.Text), [A8:A93]), 0)
If Not IsError(ret) Then TextBox2.Text = [A9].Cells(ret - 1, 4).Value
End Sub


_________________
With regards,
Colo

[ This Message was edited by: Colo on 2002-05-14 23:35 ]
Colo is offline   Reply With Quote
Old May 15th, 2002, 01:02 AM   #4
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

Thank you TsTom worked great, now for the next part.

For Each c In Range("A8:A93")
Debug.Print c.Value
If c.Value = Val(TextBox1) Then
Cells(c.Row, 4) = TextBox4
Exit For
End If
Next
Now I need to check that cell "Cells(c.Row,4) = TextBox4" if it is not blank then I need to insert a row and enter the data into the new row 4th column. But only if the cell is not blank, if it is blank then insert the data into the cell. Then after that I need to have the Range("A8:A93") increased by one to be Range("A8:A93").

What I am trying to accomplish is this.
I have the cells A8:A93 that contain a number 1-85 and the cell in column d will contain a figure for that number. When the user enters a number into the textbox1 (1-85) and then enters a figure into textbox4 the figure will be put into column d that matches the number the user entered into textbox1. But if the user enters the same number in textbox1 twice or more I need for a new row to be inserted so that it will keep more than one entry for each number (1-85). Right now all I can do is overwrite the data each time.
If I enter number 1 into textbox1 and 15.00 into textbox4, the code puts 15.00 into row 8 column D because the number 1 is in Row 8 column A. But if I enter 1 again and 25.00 in the other textbox the code will overwrite the 15.00 with the 25.00, I need for it to be put under the 15.00 hence the inserting of a new row.

If I am doing the hard way please someone slap me with an easier way.

thanks,


__________________
I appreciate the help from everyone at Mr. Excel.

viper
viper is offline   Reply With Quote
Old May 15th, 2002, 01:07 AM   #5
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

Thanks Colo,
__________________
I appreciate the help from everyone at Mr. Excel.

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

Hey Viper.
I don't know what you are doing, so I can't tell if there is a better way...
For the time being, name your range so that when rows are added, the named range will automatically expand...

In this ex. your named range for A8:A93 is "YourRange"



Private Sub CommandButton1_Click()
Dim c
For Each c In Range("YourRange")
Debug.Print c.Value
If c.Value = Val(TextBox1) Then
If Cells(c.Row, 4) <> "" Then
Cells(c.Row + 1, 4).Rows.EntireRow.Insert
Cells(c.Row + 1, 4) = TextBox2
Else
Cells(c.Row, 4) = TextBox2
End If
Exit For
End If
Next
End Sub



Tom
Tom Schreiner 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 07:34 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