+ Reply to Thread
Results 1 to 10 of 10

VBA to insert row number.

  1. #1
    Registered User
    Join Date
    08-27-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2013
    Posts
    6

    VBA to insert row number.

    Hello All!

    I need some help...

    I have four columns in a spreadsheet:

    Time In (A1)
    Name (B1)
    Company (C1)
    Time Out (D1)

    Currently, I have it set to where when I type a Name in the Name Column, the time automatically generates in the Time In Column, using this code...

    Please Login or Register  to view this content.
    I want to add a new row labeled Wristband #.

    So the rows would now be:

    Wristband # (A1)
    Time In (B1)
    Name (C1)
    Company (D1)
    Time Out (E1)

    I want the same thing to happen as the time, except for the ROW NUMBER to automatically appear in the Wristband # Column.

    EXAMPLE

    I type "John Doe" in C142, "11:42 AM" Appears in B142, and then "142" Appears in A142.

    I use the row number to assign wristbands to people, and when I sort the employees they don't always appear on the row they started on; which makes their wristband number different than their new row number. This way, I could sort them in alphabetical order, time-in, and their Wristband number would still be the same; even though the row number has changed.

    Can someone help me make this work?

  2. #2
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: VBA to insert row number.

    Hello
    Maybe something like the following code would work for you:

    Please Login or Register  to view this content.
    Hope this helps.
    DBY

  3. #3
    Registered User
    Join Date
    08-27-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2013
    Posts
    6
    Quote Originally Posted by DBY View Post
    Hello
    Maybe something like the following code would work for you:

    Please Login or Register  to view this content.
    Hope this helps.
    DBY
    Thanks for the quick response!! I am getting a runtime error," Application-defined or object-defined error"

    I'm not sure what's wrong. Thank you!

  4. #4
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: VBA to insert row number.

    Sorry, I can't replicate that error on my test workbook, it seems to work ok. For the Lrow variable I do reference Sheet1, that's not needed but I don't think that accounts for the error you're getting. Can you upload a sample file with the error?

  5. #5
    Registered User
    Join Date
    08-27-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2013
    Posts
    6
    Quote Originally Posted by DBY View Post
    Sorry, I can't replicate that error on my test workbook, it seems to work ok. For the Lrow variable I do reference Sheet1, that's not needed but I don't think that accounts for the error you're getting. Can you upload a sample file with the error?
    I tried attaching it, hopefully it works.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-27-2011
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: VBA to insert row number.

    Try this. I have inserted a line into your existing code which writes the row number in column C.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-27-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2013
    Posts
    6
    Quote Originally Posted by StevePM View Post
    Try this. I have inserted a line into your existing code which writes the row number in column C.

    Please Login or Register  to view this content.
    That is giving me the same error as before

  8. #8
    Registered User
    Join Date
    08-27-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2013
    Posts
    6
    Quote Originally Posted by fmanfisher View Post
    That is giving me the same error as before
    I got it! I accidentally changed the offset to be - 2 instead of - 1 thank you so much!!

  9. #9
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: VBA to insert row number.

    Hi
    In this row you have:

    Please Login or Register  to view this content.
    It should be:

    Please Login or Register  to view this content.
    You had 1 up. It should be letter L and UP

    DBY

  10. #10
    Registered User
    Join Date
    11-27-2011
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: VBA to insert row number.

    Quote Originally Posted by fmanfisher View Post
    I got it! I accidentally changed the offset to be - 2 instead of - 1 thank you so much!!
    No problem, I'm glad to have helped.

+ 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. Replies: 7
    Last Post: 10-14-2016, 05:33 PM
  2. Replies: 2
    Last Post: 09-11-2016, 12:39 PM
  3. Replies: 1
    Last Post: 09-11-2016, 12:39 PM
  4. Formula for If the last 5 cells did not contain number 11, insert number 11
    By ceexcee1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-06-2014, 07:08 AM
  5. [SOLVED] insert a number in sheet1, add that number of rows in sheet2 and sheet3
    By dishguy05 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-07-2014, 04:55 PM
  6. Insert Column then insert designated number
    By houseguy007 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-18-2010, 08:15 PM
  7. [SOLVED] Insert Next? Or insert a variable number of records...how?
    By Tom MacKay in forum Excel General
    Replies: 0
    Last Post: 04-20-2006, 05:50 PM

Tags for this Thread

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