+ Reply to Thread
Results 1 to 5 of 5

Auto Serial Number Using VBA

  1. #1
    Forum Contributor
    Join Date
    11-07-2005
    Posts
    280

    Auto Serial Number Using VBA

    Hi all,

    I use the following formula to get an Auto Serial Number for all cells in column A.

    Please Login or Register  to view this content.
    My question is >> how can I get an Auto Serial Number for all cells in column A by using VBA.

    I hope that my quesion is clear,

    Thank you,

  2. #2
    JMay
    Guest

    Re: Auto Serial Number Using VBA

    Here's one way: (In a standard module)

    Sub Foo()
    Range("B2").Select
    lrow = Cells(Rows.Count, 2).End(xlUp).Row
    Set myrange = Range(Cells(2, 2), Cells(lrow, 2))
    For Each cell In myrange
    cell.Offset(0, -1).Value = i + 1
    i = i + 1
    Next cell
    End Sub





    "LoveCandle" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hi all,
    >
    > I use the following formula to get an Auto Serial Number for all cells
    > in column A.
    >
    >
    > Code:
    > --------------------
    > =IF(B2<>"",ROW()-1,"")
    > --------------------
    >
    >
    > My question is >> how can I get an Auto Serial Number for all cells in
    > column A by using VBA.
    >
    > I hope that my quesion is clear,
    >
    > Thank you,
    >
    >
    > --
    > LoveCandle
    > ------------------------------------------------------------------------
    > LoveCandle's Profile:
    > http://www.excelforum.com/member.php...o&userid=28612
    > View this thread: http://www.excelforum.com/showthread...hreadid=487565
    >




  3. #3
    Bob Phillips
    Guest

    Re: Auto Serial Number Using VBA

    Is this what you want

    For i = 2 To Cells(Rows.Count,"B").End(xlUp).Row
    If Cells(i,"B").Value <> "" Then
    Cells(i,"A").Value = i - 1
    End If
    Next i

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "LoveCandle" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hi all,
    >
    > I use the following formula to get an Auto Serial Number for all cells
    > in column A.
    >
    >
    > Code:
    > --------------------
    > =IF(B2<>"",ROW()-1,"")
    > --------------------
    >
    >
    > My question is >> how can I get an Auto Serial Number for all cells in
    > column A by using VBA.
    >
    > I hope that my quesion is clear,
    >
    > Thank you,
    >
    >
    > --
    > LoveCandle
    > ------------------------------------------------------------------------
    > LoveCandle's Profile:

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




  4. #4
    Registered User
    Join Date
    04-17-2016
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    2
    For i = 2 To Cells(Rows.Count,"B").End(xlUp).Row
    If Cells(i,"B").Value <> "" Then
    Cells(i,"A").Value = i - 1
    End If
    Next i
    Dear Sir how can I use this formula for Auto Serial number for specified range for exp A3 to A33 please help
    Thanks

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Auto Serial Number Using VBA

    Pls open in new thread. Its 17-year old thread.
    Quang PT

+ 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