+ Reply to Thread
Results 1 to 4 of 4

Macro: Assigning an ID number to each row in Excel 2010

  1. #1
    Registered User
    Join Date
    09-02-2014
    Location
    Calgary, Canada
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Macro: Assigning an ID number to each row in Excel 2010

    Hi,

    I have a worksheet with multiple tasks that need to be updated on a monthly basis.

    Im trying to find a formula or macro that assigns a number in column A to each row in that spreadsheet in the format of 2014-01, 2014-02, 2014-03...

    Also, that number needs to be specific to that row even when being sorted.

    Thanks for your help!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro: Assigning an ID number to each row in Excel 2010

    Welcome to the forum.

    Enter 2014-01 in the first cell and drag down.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    09-02-2014
    Location
    Calgary, Canada
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Re: Macro: Assigning an ID number to each row in Excel 2010

    Thats what I have been doing, however I want to have that ID number assigned to that row so it doesnt change even after it has been sorted.
    Also, when another line is added i want it to automatically update the next line in the sequence.

    I was trying to work with this macro, but I cant seem to figure out how to set it to the format i want.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 Then 'This is the column that causes the ID to be created
    'This uses the target offset so it assumes in two spots below that the column to update is "A" and
    'that the column is one position to the left of the target column above
    If Target.Offset(0, -1).Value = "" Then
    Target.Offset(0, -1).Value = Application.WorksheetFunction.Max(Columns("A")) + 1
    End If
    End If

    End Sub

    Function Max_Each_Column(Data_Range As Range) As Integer
    Dim TempArray() As Double, i As Long
    If Data_Range Is Nothing Then Exit Function
    With Data_Range
    ReDim TempArray(1 To .Columns.Count)
    For i = 1 To .Columns.Count
    TempArray(i) = Application.Max(.Columns(i))
    Next
    End With
    Max_Each_Column = TempArray
    End Function


    Thanks,

    Ali

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro: Assigning an ID number to each row in Excel 2010

    If you want the number to remain the same after sorting, don't sort that column.

    Or use a formula: = "2014-" & text(row()-1, "00")

  5. #5
    Registered User
    Join Date
    09-02-2014
    Location
    Calgary, Canada
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Re: Macro: Assigning an ID number to each row in Excel 2010

    That will still change once I sort.

    I want to keep the each of the IDs (2014-01, 2014-02, 2014-03) specific to each of the respective rows.
    The macro above gives me what I want, but im unsure how to set it to this format: 2014-01

+ 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: 3
    Last Post: 12-16-2013, 05:16 AM
  2. Problem with Assigning a Macros to the Ribbon or Quick Access Bar in Excel 2010
    By Benefitus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2013, 08:12 AM
  3. [SOLVED] Macro for Auto Inserting a Number Incrementally (+1) in the footer of Excel 2010
    By bobbyd98682 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2012, 03:38 PM
  4. Searching the particular numberfrom excel'2010 table and locate the number in Word'2010
    By jaffirahamed1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2012, 08:09 AM
  5. Assigning a Row Number to a variable in a macro
    By Neil07979 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-19-2009, 08:17 AM

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