Results 1 to 9 of 9

Thread: [RESOLVED] Excel: Can this be simplified?

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Resolved [RESOLVED] Excel: Can this be simplified?

    Is there a shorter / more direct way to do this?
    VB Code:
    1. Sub TestSub()
    2.    'TestCell is the name of a specific
    3.    'cell containing input data
    4.     x = ThisWorkbook.Names("TestCell")
    5.     y = Range(x).Value
    6.     Cells(12,9).Value = y*y
    7. End Sub
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Excel: Can this be simplified?

    What is your definition of "input data"? I.e what are you trying to test for?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Excel: Can this be simplified?

    Quote Originally Posted by DKenny
    What is your definition of "input data"? I.e what are you trying to test for?
    For example, the user inputs a numeric value in the cell with name "TestCell".

    To summarize my recent VBA related posts, what I'm trying to do -the entire Excel project I'm currently working on- is a spreadsheet where the user is required to input numerical data to a number of cells and a numerical result is given after a number of calculations are performed involving both math formulas, interpolation in lookup tables, macros, etc.

    I'm still in the interface design phase. This means that occasionally I realize I must allow for additional input just above (or to the left) of a cell that's being referenced in another cell or in a macro statement. So every now and then I must insert rows or columns. That's why I need to use a trick to forget about updating all these references manually in the macros or in the cells.

    I want to protect the spreadsheet from being tampered with and at the same time I want it to be very user-friendly (that's why I'd like to tab around the allowed cells only).

    In one word, I'm aiming toward perfection but I'm taking great pains because I've seldom used VBA in the past. In fact, whenever I have to undertake a project like this I'm always hesitating and spend plenty of time trying to decide whether I'm going to use a spreadsheet or a stand-alone VB application. Maybe I should have chosen the latter option in view of the difficulties I'm having.
    Last edited by krtxmrtz; Jun 16th, 2006 at 04:07 AM.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Excel: Can this be simplified?

    The easiest way to ensure that a use entrers a numeric value into a cell is to not use code at all!
    Have a look at the 'Validation' command on the 'Data' menu. I use this built-in data validation on all my Excel apps, its easy to configure and implement. Have a look at the help file entry for "Prevent invalid data entry in a worksheet"
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Excel: Can this be simplified?

    Another option (probably a bit late now) is to use a userform...


    As for the question - did you need the user to enter a second item - or just have somewhere to hold a value? if the latter, store in a variable?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  6. #6

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Excel: Can this be simplified?

    Quote Originally Posted by DKenny
    The easiest way to ensure that a use entrers a numeric value into a cell is to not use code at all!
    Have a look at the 'Validation' command on the 'Data' menu. I use this built-in data validation on all my Excel apps, its easy to configure and implement. Have a look at the help file entry for "Prevent invalid data entry in a worksheet"
    Well, I didn't mean exactly that. The spreadsheet doesn't have to be foolproof because the user knows what type / format of data must be used. The sheet protection I need is for those cells having formulas. In an earlier and less sophisticated version I made some time ago I would sometimes type to the wrong cell and delete important information.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  7. #7

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Excel: Can this be simplified?

    Quote Originally Posted by Ecniv
    Another option (probably a bit late now) is to use a userform...
    In this case I'd probably do it in pure VB.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  8. #8
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Excel: Can this be simplified?

    You could use 1 line:

    VB Code:
    1. Cells(12,9).Value = (Range("TestCell").value)^2


    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  9. #9

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Excel: Can this be simplified?

    Quote Originally Posted by zaza
    You could use 1 line:

    VB Code:
    1. Cells(12,9).Value = (Range("TestCell").value)^2


    zaza
    You're right...
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width