Consulting

Results 1 to 12 of 12

Thread: Automatically entering data in cells with Excel 2003

  1. #1
    VBAX Regular
    Joined
    Aug 2006
    Posts
    7
    Location

    Automatically entering data in cells with Excel 2003

    I'm sorry if this has been posted before, but I am having difficulty finding an answer that works for me. I'd like to write a simple excel file that would do 3 things.

    1) Automatically fill in the next sequential row number every time a cell is selected in the A column. ie. after filling row #1 with data and hitting enter, cell A2 would automatically fill with the number 2, and then, after hitting enter, A3 would automatically fill with the number 3, etc.

    2) Automatically fill in today's date (static, so that the value will not change tomorrow) every time a cell is selected in the B column. I've tried adding a couple different versions of macros/module to the VBAproject, but I'm having difficulty getting that to work, and perhaps I need step-by-step directions. One thing I didn't understand is, does a macro have to be manually started (ie. Tools>Macro>Macros>Run) every time you select a cell in order for it to run?

    3) Automatically fill in a word every time a cell is selected in the C column, such that if I hit Tab the word will remain or if I hit Backspace I can type in a different word.

    I'm pretty new to Excel, so I'm hoping these are easy questions!

    Thanx for your help

    - Scott

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Cross posted: http://www.puremis.net/excel/cgi-bin...num=1155828891

    Dipdog,
    Click here for an explanation of cross-posting
    http://www.excelguru.ca/node/7
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Regular
    Joined
    Aug 2006
    Posts
    7
    Location
    My apologies. First time anyone's ever pointed that out to me. Anyhow, I'd be grateful for your assistance.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    For what it's worth!

    [VBA]
    Option Explicit
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column = 1 Then IncrementA Target
    If Target.Column = 2 Then DateB Target
    If Target.Column = 3 Then WordC Target
    End Sub

    Sub IncrementA(Target As Range)
    If Target.Row() = 1 Then Exit Sub
    Application.EnableEvents = False
    If Target = "" And Target.Offset(-1) <> "" Then
    Target = Target.Offset(-1) + 1
    End If
    Application.EnableEvents = True
    End Sub
    Sub DateB(Target As Range)
    With Target
    .Value = Now()
    .NumberFormat = "dd/mm/yy"
    End With
    End Sub
    Sub WordC(Target As Range)
    With Target
    .Value = "ThereMustBeSomeSenseToThis,ButIDon'tSeeIt"
    End With
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Pretty nice Malcolm. Getting close to the impossible.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Maybe I'll make a KB out of it!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    VBAX Regular
    Joined
    Aug 2006
    Posts
    7
    Location

    Thanx!

    Sorry I'm late replying. That is sweet!! Thank you very much.

    - Scott

    Again, my apologies about the cross-post. Hope this helps someone else as well.

  9. #9
    VBAX Regular
    Joined
    Aug 2006
    Posts
    7
    Location

    re: justforfun.xls

    mcmackillop
    This is probably a stupid question, but I've been using and customizing the file that you attached (justforfun.xls). I noticed that the number of rows is fixed at 30. Is there an easy way to change it so it will go beyond 30 rows?

    Thanx!

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi dipdog
    The rows are just hidden, Select the worksheet and Format/Rows/Unhide
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    BTW, VeryStrange in Post 4 is the "functional" file. JustForFun is just what it says.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  12. #12
    VBAX Regular
    Joined
    Aug 2006
    Posts
    7
    Location

    re:

    Yah, I guess that was a stupid question. Thanx again!

Posting Permissions

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