+ Reply to Thread
Results 1 to 8 of 8

auto number every 4 row by code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    734

    auto number every 4 row by code

    hello
    i have this code works very well but i need adjusting and make it numbering every 4 rows i put my result in column a
    HTML Code: 
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: auto number every 4 row by code

    Hi ABDELFATTA

    See if a For Next Loop with a 4 Step works for you. Like:
    Sub Auto_Serial()
        Dim lr As Long
        Dim RowCtr As Long
        Dim PreStr As String
        Dim Ctr As Long
        
        lr = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
        PreStr = "bsj2018/"
        Ctr = 1
        
        For RowCtr = 4 To lr Step 4
            Cells(RowCtr, "A") = PreStr & Format(Ctr, "000")
            Ctr = Ctr + 1
        Next RowCtr
    
    End Sub
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: auto number every 4 row by code

    Can you also indicate what the expected result is?

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,150

    Re: auto number every 4 row by code

    Another option
    Sub Abdelfattah()
       With Range("A4:A" & Range("B" & Rows.Count).End(xlUp).Row)
          .Formula = "=if(B4="""","""",""bsj2018/""&text(counta(B$4:B4),""000""))"
          .Value = .Value
       End With
    End Sub

  5. #5
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    734

    Re: auto number every 4 row by code

    awesome Marvip greatly work

  6. #6
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    734

    Re: auto number every 4 row by code

    always codes are unique fluff the most important no loop this makes code a quick thank so much

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,150

    Re: auto number every 4 row by code

    You're welcome & thanks for the feedback.

  8. #8
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    734

    Re: auto number every 4 row by code

    sir vragg i have ever cleared the result in column a do you check my file , and do you read my post ?
    anyway Fluff and Marvip solved it

+ 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. [SOLVED] Code to Number Rows as a Sheet is Auto Updated
    By hammer2 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-25-2018, 07:50 PM
  2. how to auto add code line number in VBA Editor
    By mohan.r1980 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2017, 02:06 AM
  3. How to add auto number to this vba code
    By naylak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-31-2014, 11:30 AM
  4. [SOLVED] vba code to find last row value, add new row and auto number new row
    By kawa13 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-13-2013, 06:16 AM
  5. Auto number code
    By HOSAMNOOR in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-08-2007, 06:06 PM
  6. Auto Fill (number & its repeat in bar code) for stickers
    By Sonny Dumas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-12-2006, 01:25 AM
  7. [SOLVED] Can I auto fill a cell in one worksheet by typing a code number
    By Dave Peterson in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 06:05 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