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 Feb 25th, 2002, 11:21 AM   #1
Todd_M
Board Regular
 
Join Date: Feb 2002
Posts: 117
Default

Hi:
Im currently wiring a number of userforms so that data can be inserted to cells on a worksheet(The worksheet contains(column"d")dates from "1Jan01 to 31Dec2020) First objective is to have the user select a date from the calander control. Upon selection, a new userform appears w/ the date that was selected, in a listbox. Then the user has to enter a number($307.25 or what ever)into a text box on that same userform. The user presses a commandbutton named "OK" and I want that number pasted on a cell to the right of the date cell in the worksheet!
My problem is that im not sure how to write the code for the commandbutton() to find the date on the worksheet from the listbox date and at the same time insert the number($307.25 or what ever)into the cell just to the right(column"e") of that date on the worksheet.
Todd_M is offline   Reply With Quote
Old Feb 25th, 2002, 11:43 AM   #2
Mudface
MrExcel MVP
 
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
Default

You don't really need to store the date selected in a listbox, does the following help?

Private Sub CommandButton1_Click()

For Each c In Range("D1:D100") ' Adjust your range if necessary
If c.Value = ActiveSheet.Calendar1.Value Then
c.Offset(0, 1).Value = TextBox2.Text
Me.Hide
Exit Sub
End If
Next c

End Sub
Mudface is offline   Reply With Quote
Old Feb 25th, 2002, 05:40 PM   #3
Russell Hauf
MrExcel MVP
 
Russell Hauf's Avatar
 
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
Default

Todd,

After speaking to you via email, I think this should work for you...let me know if it does not.

-Russell


Option Explicit


Private Sub CommandButton1_Click()

Dim intRow As Integer
Dim intCol As Integer

intCol = 3 ' column C, where your dates are
intRow = 2 ' change this to the row where your dates start

' This first DO loop goes until it finds an empty column...
' this way if you enter more (or less) dates in the future,
' you don't have to change your code...
' if it's possible for the user to select a date that is
' not in your spreadsheet, then you should account for this
' in your code.
Do While Trim(Cells(intRow, intCol).Text) <> ""
If Cells(intRow, intCol).Value = Calendar1.Value Then
' You've found a matching date - now find the first
' cell to the right that is empty.
intCol = intCol + 1
Do While Trim(Cells(intRow, intCol).Text) <> ""
intCol = intCol + 1
Loop
Cells(intRow, intCol) = TextBox2.Text
Exit Do
End If
intRow = intRow + 1
Loop

' Me.Hide or whatever here

End Sub

Russell Hauf is offline   Reply With Quote
Old Feb 25th, 2002, 05:55 PM   #4
Todd_M
Board Regular
 
Join Date: Feb 2002
Posts: 117
Default

Todd_M is offline   Reply With Quote
Old Feb 25th, 2002, 06:09 PM   #5
Todd_M
Board Regular
 
Join Date: Feb 2002
Posts: 117
Default

Russell-
Thankyou for your time: I understand most of the code you have given me. As stated before via e-mail, I wrote that the code that mudface sent me and it does work with a few changes to fit my strategy. Here it is:

Private Sub CommandButton3_Click()
For Each c In Worksheets("BALANCE SHEET").Range("D1:D10000") ' Adjust your range if necessary
If c.Value = DateForm.Calendar2.Value Then
c.Offset(0, 6).Value = TextBox1.Text
Me.Hide
Exit Sub
End If
Next c
End Sub

Notice the "offset(0, 6).value" I changed this so that my text from textbox1 will be inserted 6 cells to the right of the date column. Using the same formula, what can I add in the formula to identify if the 6th cell is full, and if then, how can I get the textbox1.value into the next empty cell to the right?
Thanks again.
Todd_M is offline   Reply With Quote
Old Feb 25th, 2002, 06:15 PM   #6
Russell Hauf
MrExcel MVP
 
Russell Hauf's Avatar
 
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
Default

Quote:
On 2002-02-25 17:09, Todd_M wrote:
Russell-
Thankyou for your time: I understand most of the code you have given me. As stated before via e-mail, I wrote that the code that mudface sent me and it does work with a few changes to fit my strategy. Here it is:

Private Sub CommandButton3_Click()
For Each c In Worksheets("BALANCE SHEET").Range("D1:D10000") ' Adjust your range if necessary
If c.Value = DateForm.Calendar2.Value Then
c.Offset(0, 6).Value = TextBox1.Text
Me.Hide
Exit Sub
End If
Next c
End Sub

Notice the "offset(0, 6).value" I changed this so that my text from textbox1 will be inserted 6 cells to the right of the date column. Using the same formula, what can I add in the formula to identify if the 6th cell is full, and if then, how can I get the textbox1.value into the next empty cell to the right?
Thanks again.

Private Sub CommandButton3_Click()
For Each c In Worksheets("BALANCE SHEET").Range("D1:D10000") ' Adjust your range if necessary
If c.Value = DateForm.Calendar2.Value Then
Do While c.Offset(0,1).text <> ""
c = c.offset(0,1)
Loop
c.Offset(0, 1).Value = TextBox1.Text
Me.Hide
Exit Sub
End If
Next c
End Sub

[ This Message was edited by: Russell Hauf on 2002-02-25 17:16 ]
Russell Hauf is offline   Reply With Quote
Old Feb 25th, 2002, 06:23 PM   #7
Russell Hauf
MrExcel MVP
 
Russell Hauf's Avatar
 
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
Default

Quote:
On 2002-02-25 17:15, Russell Hauf wrote:
Quote:
On 2002-02-25 17:09, Todd_M wrote:
Russell-
Thankyou for your time: I understand most of the code you have given me. As stated before via e-mail, I wrote that the code that mudface sent me and it does work with a few changes to fit my strategy. Here it is:

Private Sub CommandButton3_Click()
For Each c In Worksheets("BALANCE SHEET").Range("D1:D10000") ' Adjust your range if necessary
If c.Value = DateForm.Calendar2.Value Then
c.Offset(0, 6).Value = TextBox1.Text
Me.Hide
Exit Sub
End If
Next c
End Sub

Notice the "offset(0, 6).value" I changed this so that my text from textbox1 will be inserted 6 cells to the right of the date column. Using the same formula, what can I add in the formula to identify if the 6th cell is full, and if then, how can I get the textbox1.value into the next empty cell to the right?
Thanks again.

Private Sub CommandButton3_Click()
For Each c In Worksheets("BALANCE SHEET").Range("D1:D10000") ' Adjust your range if necessary
If c.Value = DateForm.Calendar2.Value Then
Do While c.Offset(0,1).text <> ""
c = c.offset(0,1)
Loop
c.Offset(0, 1).Value = TextBox1.Text
Me.Hide
Exit Sub
End If
Next c
End Sub

[ This Message was edited by: Russell Hauf on 2002-02-25 17:16 ]
And you could also do this:
...
If c.Value = DateForm.Calendar2.Value Then
c.End(xlToRight).Offset(0, 1).Value = TextBox1.Text
End If
...
Russell Hauf is offline   Reply With Quote
Old Feb 25th, 2002, 06:39 PM   #8
Todd_M
Board Regular
 
Join Date: Feb 2002
Posts: 117
Default

Russell- If I set the offset value to the 22nd column from the date column(column"D"), it reads "offset(0, 22). What do I set the other two offset numbers to:
Do While c.Offset(0, 1).Text <> ""
c = c.Offset(0, 1)
So that if column 22 is not empy, then the textbox.value will go to column 23 or the next empty cell in that row?
Todd_M 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 01:57 AM.


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