+ Reply to Thread
Results 1 to 3 of 3

Incrementing numbers in a column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    Incrementing numbers in a column

    hello I have a cell value that holds how many rows I want.

    I then in D:D minus top row want to put numbers in from 1 to the value that is in the cell say B10.

    So it has a column of numbers from 1 to the value in B10 in row D.
    Also I would also like to change the background of the cells in D:D minus top row to Blue and text to white



    
    Dim Cell2 As Range, rng2 As Range, e As Long
    
    
        Set rng2 = .Range("Gamerange")
        
            For e = 2 To Games + 1
            Do Until e > Games
            Set Cell2.Value = 1
    Thank you for any help much appreciated

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,900

    Re: Incrementing numbers in a column

    I use the following to insert numbers in a spreadsheet.
    Sub AutoNumberFill()
        Dim x As Long
        Dim rn As Long
        Dim cn As String, sn As Long
        cn = InputBox("Which Column to fill?")
        
        
        rn = InputBox("How many rows to fill?")
        sn = InputBox("Which row to start fill?")
    
        Application.ScreenUpdating = False
        Application.StatusBar = "Macro Running"
        x = InputBox("What is the starting number?")
        Range(cn & sn).Select
        Do Until ActiveCell.Row = rn + sn
            If ActiveCell.EntireRow.Hidden = False Then
                ActiveCell.Value = x
                x = x + 1
            End If
            ActiveCell.Offset(1).Select
        Loop
        Application.ScreenUpdating = True
        Application.StatusBar = "Completed"
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: Incrementing numbers in a column

    How about this.

    Sub tst()
        nRows = Range("B10").Value
        With Range("D2").Resize(nRows)
            .Formula = "=Row()-1"
            .Value = .Value
            .Interior.Color = RGB(0, 0, 255)
            .Font.Color = vbWhite
        End With
    End Sub
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ 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. Incrementing numbers down a column
    By Motox in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-14-2019, 08:58 PM
  2. [SOLVED] Incrementing column letters and row numbers at different intervals
    By CrazyChipmunk in forum Excel General
    Replies: 6
    Last Post: 03-03-2017, 08:20 PM
  3. Create range of numbers on one row from incrementing numbers on multiple rows
    By mexykanu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2014, 04:40 PM
  4. incrementing a column of numbers
    By blob2 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-31-2006, 03:53 AM
  5. Incrementing Cell Numbers
    By den1s in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2006, 11:00 PM
  6. [SOLVED] Incrementing numbers
    By Floyd107 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-28-2006, 06:10 AM
  7. Incrementing Cell Numbers
    By Lance W. Grimes in forum Excel General
    Replies: 1
    Last Post: 03-08-2005, 04:06 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