Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
VB calculations
Tim,
See code snippets in-line. HTH, Bernie MS Excel MVP "timmulla" wrote in message ... Can anyone help me do the following calculations in a excel userform. I have two calendar 10.0 controls (Calendar1 and Calendar2). Calendar1.value relates to a start date and calendar2.value relates to an end date. I'm trying to have the number of days between Calendar1 and Calendar2 show up in a conrtol labeledTextBox8, when Commandbutton1 is clicked. Depends: something like: Userform1.TextBox8.Text = Userform1.Calendar2.value - Userform1.Calendar1.Value Userform1.TextBox8.Text = Userform1.Calendar2.value - Userform1.Calendar1.Value + 1 TextBox1 - Numerical user input expressed as a percentage (i.e. 10%,this is a % fee charged on an account). TextBox2 - Numerical user input expressed a dollar amount (i.e. $100,000, this is account value). TextBox3 - I'm trying to have the value of TextBox1.value * Texbox2.value show up when Commandbutton1 is clicked. UserForm1.TextBox3.Text = _ Format(Val(UserForm1.TextBox1.Text) / 100 * _ Val(UserForm1.TextBox2.Text), "00.00") TextBox4 - I'm trying to have TextBox3.value/365 show up when Commandbutton1 is clicked (This will give me a daily rate). UserForm1.TextBox4.Text = _ Format(Val(UserForm1.TextBox3.Text) / 365, "00.00") TextBox5 - I'm trying to have TextBox8.value * TextBox5.value show up when Commandbutton1 is clicked. UserForm1.TextBox5.Text = _ Format(Val(UserForm1.TextBox8.Text) * _ Val(UserForm1.TextBox5.Text), "00.00") Though be careful with this one... multiple clicks will give you problems. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
VB calculations
Tim,
Unless you have a relational database with thousands of records, you can use Excel as your database. You could use code like this to store your data: Dim myRow As Long With Worksheets("DataBase") myRow = .Cells(Rows.Count,1).End(xlUp)(2).Row .Cells(myRow,1).Value = Val(Userform1.TextBox1.Text) .Cells(myRow,2).Value = Val(Userform1.TextBox2.Text) .Cells(myRow,3).Value = Val(Userform1.TextBox3.Text) .Cells(myRow,4).Value = Val(Userform1.TextBox4.Text) 'Etc... End With And code like this to extract your data (with column A as the key value) Dim myRow As Long With Worksheets("DataBase") myRow = Application.Match(Userform1.TextBox1.Text,.Range(" A:A"),False) Userform1.TextBox2.Text = .Cells(myRow,2).Value Userform1.TextBox3.Text = .Cells(myRow,3).Value Userform1.TextBox4.Text = .Cells(myRow,4).Value 'Etc... End With Of course, you might need to format the data, and use error checking, etc. to tell when you are modifying existing data versus adding new data... HTH, Bernie MS Excel MVP "timmulla" wrote in message ... Thanks for your help Bernie, it's working great. Another question I was hoping you could answer for me is: Is it possible to have the textbox values recorded in an access data base when a user clicks the Commandbutton1 on UserForm1? I'm hoping that the textbox values can be stored in a data base as a record. I would also like to be able to retrieve the data base values back into UserForm1 upon a listbox selection. Is this possible? if so, can you recommend a good source of information to show me how to accomplish this (website/book,etc..) Thanks. -- Regards, timmulla "Bernie Deitrick" wrote: Tim, See code snippets in-line. HTH, Bernie MS Excel MVP "timmulla" wrote in message ... Can anyone help me do the following calculations in a excel userform. I have two calendar 10.0 controls (Calendar1 and Calendar2). Calendar1.value relates to a start date and calendar2.value relates to an end date. I'm trying to have the number of days between Calendar1 and Calendar2 show up in a conrtol labeledTextBox8, when Commandbutton1 is clicked. Depends: something like: Userform1.TextBox8.Text = Userform1.Calendar2.value - Userform1.Calendar1.Value Userform1.TextBox8.Text = Userform1.Calendar2.value - Userform1.Calendar1.Value + 1 TextBox1 - Numerical user input expressed as a percentage (i.e. 10%,this is a % fee charged on an account). TextBox2 - Numerical user input expressed a dollar amount (i.e. $100,000, this is account value). TextBox3 - I'm trying to have the value of TextBox1.value * Texbox2.value show up when Commandbutton1 is clicked. UserForm1.TextBox3.Text = _ Format(Val(UserForm1.TextBox1.Text) / 100 * _ Val(UserForm1.TextBox2.Text), "00.00") TextBox4 - I'm trying to have TextBox3.value/365 show up when Commandbutton1 is clicked (This will give me a daily rate). UserForm1.TextBox4.Text = _ Format(Val(UserForm1.TextBox3.Text) / 365, "00.00") TextBox5 - I'm trying to have TextBox8.value * TextBox5.value show up when Commandbutton1 is clicked. UserForm1.TextBox5.Text = _ Format(Val(UserForm1.TextBox8.Text) * _ Val(UserForm1.TextBox5.Text), "00.00") Though be careful with this one... multiple clicks will give you problems. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
MPG Calculations | Excel Worksheet Functions | |||
age calculations | Excel Discussion (Misc queries) | |||
#N/A in calculations | Excel Worksheet Functions | |||
Help with calculations | Excel Worksheet Functions | |||
! in Calculations | Excel Discussion (Misc queries) |