Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7737075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:54:18+00:00 2026-06-01T07:54:18+00:00

The code below is working. It will progress through all columns in the sheet

  • 0

The code below is working. It will progress through all columns in the sheet and change the data within it to a number of fixed length based on the number found in the 2nd row.

My issue is that it selects the entire column when doing so. This is a problem for me since I have 4 header rows that I do not want converted.

My first thought was to offset/resize a selection and apply changes to all cells, but I’m simply having no luck doing that.

Can anyone modify this code to ignore the first 4 header rows as it progresses through the columns?

Note: lastCol is a separate function that simply returns an integer value with the number of the last used column on the sheet.

Sub FormatFixedNumber()

    Dim i As Long

    Application.ScreenUpdating = False

    For i = 1 To lastCol 'replace 10 by the index of the last column of your spreadsheet
        With Columns(i)
            .NumberFormat = String(.Cells(2, 1), "0") 'number length is in second row
        End With
    Next i
    Application.ScreenUpdating = True

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:54:20+00:00Added an answer on June 1, 2026 at 7:54 am

    This should do it. I added a Constant to hold the header rows count.

    EDIT: Added code to just go to last row as requested. Also checks that LastRow is greater than HEADER_ROWS. And fixed some convoluted adding and subtracting of the HEADER_ROWS in the Resize/Offset.

    Sub FormatFixedNumber()
    Const HEADER_ROWS As Long = 4
    Dim i As Long
    Dim LastRow As Long
    
    Application.ScreenUpdating = False
    For i = 1 To LastCol    'replace 10 by the index of the last column of your spreadsheet
        With Columns(i)
            LastRow = .Cells(Rows.Count).End(xlUp).Row
            If LastRow > HEADER_ROWS Then
                With .Resize(LastRow - HEADER_ROWS).Offset(HEADER_ROWS)
                    .NumberFormat = String(.EntireColumn.Cells(2, 1), "0")    'number length is in second row
                End With
            End If
        End With
    Next i
    Application.ScreenUpdating = True
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the below code is working fine if the user enters the USN number that
I'm trying to get the code below working so that it will call a
The code below will print all of the text from the sample text file
The code below working for only first div. I can't display other divs when
Code below is working well as long as I have class ClassSameAssembly in same
The code below is working, but with a problem I do not understand. When
The code below is working nearly flawlessly, however my value for page title on
Code below is not working as expected to detect if it is in design
Technology Used:- Asp.Net 2.0 Code:- See Below Description:- hello code given below is working
The below code is working great for handling errors for text fields in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.