+ Reply to Thread
Results 1 to 12 of 12

Please help a newbie to VB!!!

  1. #1
    Registered User
    Join Date
    06-23-2005
    Posts
    86

    Please help a newbie to VB!!!

    Hi all

    Can anyone help me please?

    I want to be able to run a macro in an excel spreadsheet that will include a pop up msgbox that says "enter a value" and then a user can put a value in and then i want it to put that value in Cell A1 (For Example). This could be either a numeric number or a date field (eg 31/12/2006).
    As I am a newbie to this I am struggling. The rest of the macro I have done through recorder in excel, can anyone help me???

    Many thanks for reading
    Cheers and all the best
    Mark

  2. #2
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    Try:

    [a1] = Application.InputBox("Enter a value")

    This will accept any value from an inputbox and place it in A1. To force the inputbox to only accept a number:

    [a1] = Application.InputBox("Enter a value", , , , , , , 1)

    this will display an error message and return FALSE if the value isn't a number.

    The first example will display a valid date in the standard format, but will also accept text values. The second will accept dates but convert them into numbers (e.g. 06/06/2006 will be displayed as 38874, so you'd have to tell your macro to format it accordingly)

    Hope this helps
    Col

  3. #3
    Mike Archer
    Guest

    RE: Please help a newbie to VB!!!

    Sub GetValue()
    Dim myVar as variant

    myVar = InputBox("Enter a Value")

    Range("A1").value = myVar

    End Sub

    Or skip the variable:

    Sub GetValue()

    Range("A1").Value = InputBox("Enter a Value")

    End sub

    --
    Thanks,
    Mike


    "certain_death" wrote:

    >
    > Hi all
    >
    > Can anyone help me please?
    >
    > I want to be able to run a macro in an excel spreadsheet that will
    > include a pop up msgbox that says "enter a value" and then a user can
    > put a value in and then i want it to put that value in Cell A1 (For
    > Example). This could be either a numeric number or a date field (eg
    > 31/12/2006).
    > As I am a newbie to this I am struggling. The rest of the macro I have
    > done through recorder in excel, can anyone help me???
    >
    > Many thanks for reading
    > Cheers and all the best
    > Mark
    >
    >
    >
    > --
    > certain_death
    > ------------------------------------------------------------------------
    > certain_death's Profile: http://www.excelforum.com/member.php...o&userid=24561
    > View this thread: http://www.excelforum.com/showthread...hreadid=548915
    >
    >


  4. #4
    John
    Guest

    Re: Please help a newbie to VB!!!

    Mark,

    Have a go with this:

    Sub InputValue()
    Application.ActiveSheet.Range("A1").Value = InputBox("Enter a value")
    End Sub

    Best regards

    John

    "certain_death" <certain_death.28zb11_1149594303.9491@excelforum-nospam.com>
    wrote in message
    news:certain_death.28zb11_1149594303.9491@excelforum-nospam.com...
    >
    > Hi all
    >
    > Can anyone help me please?
    >
    > I want to be able to run a macro in an excel spreadsheet that will
    > include a pop up msgbox that says "enter a value" and then a user can
    > put a value in and then i want it to put that value in Cell A1 (For
    > Example). This could be either a numeric number or a date field (eg
    > 31/12/2006).
    > As I am a newbie to this I am struggling. The rest of the macro I have
    > done through recorder in excel, can anyone help me???
    >
    > Many thanks for reading
    > Cheers and all the best
    > Mark
    >
    >
    >
    > --
    > certain_death
    > ------------------------------------------------------------------------
    > certain_death's Profile:
    > http://www.excelforum.com/member.php...o&userid=24561
    > View this thread: http://www.excelforum.com/showthread...hreadid=548915
    >




  5. #5
    Bob Phillips
    Guest

    Re: Please help a newbie to VB!!!

    val = InputBox("Enter a value")
    Range("A1").Value = val


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "certain_death" <certain_death.28zb11_1149594303.9491@excelforum-nospam.com>
    wrote in message
    news:certain_death.28zb11_1149594303.9491@excelforum-nospam.com...
    >
    > Hi all
    >
    > Can anyone help me please?
    >
    > I want to be able to run a macro in an excel spreadsheet that will
    > include a pop up msgbox that says "enter a value" and then a user can
    > put a value in and then i want it to put that value in Cell A1 (For
    > Example). This could be either a numeric number or a date field (eg
    > 31/12/2006).
    > As I am a newbie to this I am struggling. The rest of the macro I have
    > done through recorder in excel, can anyone help me???
    >
    > Many thanks for reading
    > Cheers and all the best
    > Mark
    >
    >
    >
    > --
    > certain_death
    > ------------------------------------------------------------------------
    > certain_death's Profile:

    http://www.excelforum.com/member.php...o&userid=24561
    > View this thread: http://www.excelforum.com/showthread...hreadid=548915
    >




  6. #6
    Registered User
    Join Date
    06-23-2005
    Posts
    86

    Col/Mike/Bob/John Many thanks!!!

    Hey guys

    That's brilliant thank you so much...

    As a further help (please) can I make the value that is returned in Cell A1 from the input box, copy down the same number of lines in Column A as some corresponding data in Column B. For example, if I had 25 lines of data in column B can I get the value in A1 to copy down to A25 and stop. (This could be a random amount of lines in Col B each time)

    Hope I make some sense here..........

    Thanks a lot guys and great helpful forum...
    Cheers
    Mark

  7. #7
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    range([a1], cells([b1].end(xldown), 1)) = application.inputbox("Enter a value")


    C

  8. #8
    Registered User
    Join Date
    06-23-2005
    Posts
    86

    Error?

    Hi Col

    Am getting "Run Type Error 13" - "Type mismatch"

    Am I doing anything wrong?

    Thanks
    Mark

  9. #9
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    Without seeing more of your code I dunno... This happens when you're comparing different types of data, e.g.:

    if "a string" <> 0 then

    If you post up the macro causing the probs I'll have a look.

  10. #10
    Bob Phillips
    Guest

    Re: Please help a newbie to VB!!!

    Dim iLastRow As Long
    Dim val

    val = InputBox("Enter a value")
    Range("A1").Value = val
    iLastRow = Cells(Rows.Count, "B").End(xlUp).Row
    Range("A1").AutoFill Range("A1").Resize(iLastRow)



    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "certain_death" <certain_death.28zehy_1149598804.5545@excelforum-nospam.com>
    wrote in message
    news:certain_death.28zehy_1149598804.5545@excelforum-nospam.com...
    >
    > Hey guys
    >
    > That's brilliant thank you so much...
    >
    > As a further help (please) can I make the value that is returned in
    > Cell A1 from the input box, copy down the same number of lines in
    > Column A as some corresponding data in Column B. For example, if I had
    > 25 lines of data in column B can I get the value in A1 to copy down to
    > A25 and stop. (This could be a random amount of lines in Col B each
    > time)
    >
    > Hope I make some sense here..........
    >
    > Thanks a lot guys and great helpful forum...
    > Cheers
    > Mark
    >
    >
    >
    > --
    > certain_death
    > ------------------------------------------------------------------------
    > certain_death's Profile:

    http://www.excelforum.com/member.php...o&userid=24561
    > View this thread: http://www.excelforum.com/showthread...hreadid=548915
    >




  11. #11
    Registered User
    Join Date
    06-23-2005
    Posts
    86

    Bob and Col - Many thanks!!

    Hey guys,
    That exactly what I need...thanks very much!!!

    Am really interested in getting into this sort of thing....could you recommend a good way of learning VB from scratch at beginner level.....

    This could help me so much in my job!!

    Thanks again
    Take it easy!!
    Mark

  12. #12
    Bob Phillips
    Guest

    Re: Please help a newbie to VB!!!

    take a look at http://www.mvps.org/dmcritchie/excel/getstarted.htm

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "certain_death" <certain_death.290v9y_1149667202.1256@excelforum-nospam.com>
    wrote in message
    news:certain_death.290v9y_1149667202.1256@excelforum-nospam.com...
    >
    > Hey guys,
    > That exactly what I need...thanks very much!!!
    >
    > Am really interested in getting into this sort of thing....could you
    > recommend a good way of learning VB from scratch at beginner
    > level.....
    >
    > This could help me so much in my job!!
    >
    > Thanks again
    > Take it easy!!
    > Mark
    >
    >
    >
    > --
    > certain_death
    > ------------------------------------------------------------------------
    > certain_death's Profile:

    http://www.excelforum.com/member.php...o&userid=24561
    > View this thread: http://www.excelforum.com/showthread...hreadid=548915
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1