Serving the Quantitative Finance Community

 
User avatar
martingull
Topic Author
Posts: 0
Joined: April 15th, 2010, 6:11 am

Textbox dictates the range of timeseries VBA

October 14th, 2010, 5:24 pm

Hi!I have written a short finance program which needs improved user-friendlyness. I want the user to be able to write, in a text box, which cell the program should start and where it should end. Its a timeseries program so it should look like B2 to B100.My problem is that i have built the program such thatArow = Application.ActiveSheet.Range("b2").RowBrow = Application.ActiveSheet.Range("b729").RowAcol = Application.ActiveSheet.Range("b2").Columnis used to define the location of the timeseries. So how make b2 and b729 user defined. I want the user to be able to change the values with a textbox. I cant have the users opening the code everytime they want to change this. So please help me out with this trivial thing.Hope someone can help me out.
 
User avatar
Hansi
Posts: 41
Joined: January 25th, 2010, 11:47 am

Textbox dictates the range of timeseries VBA

October 14th, 2010, 6:27 pm

Range can take in a string as an input argument so simply collect the inputs from the UserForm and supply it to the procedure.If the Userform has an input box, a run button and then an event handler for clicking a run button then you'd make clicking the run button verify the user input being valid and then call your main procedure with the verified inputs as string and then just set the row with Arow = Application.ActiveSheet.Range(strInputA).Row etc.
 
User avatar
jpsnj
Posts: 0
Joined: February 12th, 2008, 2:42 pm

Textbox dictates the range of timeseries VBA

October 15th, 2010, 12:12 pm

You can use the Application.Inputbox function to prompt the user to select a range. Note: The Application.Inputbox is different than the VBA InputBox.Using this method, the user can either manually enter a range such as B2:B500 or select it with the mouse.A couple of examples are below:Sub SelectRange() Dim rng As Range On Error GoTo x: Set rng = Application.InputBox(Prompt:="Select Range", Type:=8) rng.Value = "ABC" Exit Subx: If Err = 424 Then MsgBox "Cancel Selected" End IfEnd SubSub SelectRange2() Dim rng As Range Dim c As Range, ctr As Long On Error GoTo x: Set rng = Application.InputBox(Prompt:="Select Range", Type:=8) For Each c In rng.Cells ctr = ctr + 1 c.Value = ctr Next Exit Subx: If Err = 424 Then MsgBox "Cancel Selected" End IfEnd Sub
Last edited by jpsnj on October 14th, 2010, 10:00 pm, edited 1 time in total.
 
User avatar
spursfan
Posts: 2
Joined: October 7th, 2001, 3:43 pm

Textbox dictates the range of timeseries VBA

October 15th, 2010, 2:02 pm

The function OFFSET is also worth looking at
 
User avatar
martingull
Topic Author
Posts: 0
Joined: April 15th, 2010, 6:11 am

Textbox dictates the range of timeseries VBA

November 3rd, 2010, 6:52 pm

Ok. Thank you guys ill lokk into this.Hope it works out!!!