+ Reply to Thread
Results 1 to 7 of 7

Vba code to autofit column when text is entered & time stamp entry for alternating columns

  1. #1
    Registered User
    Join Date
    11-17-2013
    Location
    montana
    MS-Off Ver
    Excel 2010
    Posts
    6

    Vba code to autofit column when text is entered & time stamp entry for alternating columns

    Thanks in advance for any help!

    I am trying to create a vba code that will do 2 things. I need the columns to auto fit after data entry and a time stamp in the previous column from the location when the data is entered. I attached the file.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Miroslav R.'s Avatar
    Join Date
    05-16-2013
    Location
    NMnV, Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    479

    Re: Vba code to autofit column when text is entered & time stamp entry for alternating col

    Hi there,

    place this in WorkSheet_Change event:
    Please Login or Register  to view this content.
    or here is Your sample:
    officer tracking.xlsm

    Does this solution match Your requirements?
    Regards
    Miroslav R.

    (If You like my solutions, feel free to add reputation.)

  3. #3
    Registered User
    Join Date
    05-16-2014
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Vba code to autofit column when text is entered & time stamp entry for alternating col

    What does "IF" part of code do here. When i use this part of code alone
    Please Login or Register  to view this content.
    i get a 1004 error. Just curious as to how it works.Thanks

  4. #4
    Valued Forum Contributor Miroslav R.'s Avatar
    Join Date
    05-16-2013
    Location
    NMnV, Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    479

    Re: Vba code to autofit column when text is entered & time stamp entry for alternating col

    Hi there,
    It is because this code is assigned to Worksheet_Change event. I words:
    If You enter something in cell A4, then timestamp should be recorded to cell A3. But recording timestamp to A3 triggers another change event, and if
    Please Login or Register  to view this content.
    stands alone (without IF), the code records another timestamp in A3-1 = A2. Then another change event with timestamp to A1 and finaly You do not have cell A0... And this is Your 1004 error.

    So You have to use IF to stop all that triggering after 1st timestamp. The IF says to excel change event, that only if value is entered in column which can be divided by 2 without any rest, record timestamp to cell on the left. And this only for column with number 4 and higher.

    Is it understandable?

  5. #5
    Registered User
    Join Date
    05-16-2014
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Vba code to autofit column when text is entered & time stamp entry for alternating col

    Thank you so much.. if i use the IF part without -2
    Please Login or Register  to view this content.
    i feel it works in same way. Is it correct?

    Also am new to macro and interested in programming. I just browse through forums and look at solutions provided by you guys. How come you come with these kind of beautiful solutions. Does it come with practise or does it need extra grey matter which am not if i have

  6. #6
    Valued Forum Contributor Miroslav R.'s Avatar
    Join Date
    05-16-2013
    Location
    NMnV, Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    479

    Re: Vba code to autofit column when text is entered & time stamp entry for alternating col

    Hi there,

    without '-2' it will work in the same way... It is a rest from my testing...
    BUT when I look at that now, better You add new condition for IF and finaly the IF row has to look like:
    Please Login or Register  to view this content.
    because when You write something to col B, it should not write timestamp in col A.
    Pls rewrite that line in Your workbook.

  7. #7
    Registered User
    Join Date
    05-16-2014
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Vba code to autofit column when text is entered & time stamp entry for alternating col

    Yes fine i would take it and you did not answer my second part of question. Not sure if its allowed here though

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Time stamp an entry
    By gjjh25 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-17-2014, 10:36 AM
  2. [SOLVED] Automatic Time Stamp when data entered into a cell
    By Shaliza Riley in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-19-2013, 12:15 PM
  3. Replies: 1
    Last Post: 02-27-2013, 06:18 PM
  4. Replies: 2
    Last Post: 02-23-2013, 03:58 PM
  5. Excel 2007 : Time Stamp: Every time data is entered
    By otanii in forum Excel General
    Replies: 1
    Last Post: 08-04-2011, 05:29 PM

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