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

  • SEARCH
  • Home
  • 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 6920595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:10:04+00:00 2026-05-27T10:10:04+00:00

I’m working with an excel book containing a large number of sheets; the first

  • 0

I’m working with an excel book containing a large number of sheets; the first sheet is linked to an external program and pulls in data via an external function, and the number of lines imported varies significantly.

This block data is the disseminated over a number of subsequent sheets. The first step has been to populate column A (row name) with the number of rows in sheet 1. From here the data is split over a number of columns (currently B->L). The top row uses an IF() function to populate the first row, and I’m looking to write a clean macro to copy this formula to row x (which varies with each data import refresh) and then paste values for a manageable file size.

Here’s what I’ve got so far; it works, but it’s fairly (read: VERY!) clumsy:

Sub Refresh_Data()  
    Sheets("Sheet2").Select  
    ActiveWindow.ScrollWorkbookTabs Sheets:=13  
    Sheets(Array("Sheet2" ... "Sheet25")).Select     
    Sheets("Sheet2").Activate  
    Sheets("Sheet25").Select Replace:=False  
    Range("B1:L1").Select  
    Selection.Copy  
    Range("__B2:B1000__").Select  
    ActiveSheet.Paste  
    Application.Calculate  
    ActiveWindow.ScrollWorkbookTabs Position:=xlFirst  
    Sheets(Array("Sheet2" ... "Sheet25")).Select  
    Sheets("Sheet2").Activate  
    Sheets("Sheet25").Select Replace:=False  
    Sheets("Sheet2").Select  
    Range("B3").Select  
    Sheets(Array("Sheet2" ... "Sheet25")).Select  
    Sheets("Sheet2").Activate  
    Sheets("Sheet25").Select Replace:=False  
    Range("B3:L4").Select  
    Range("__B2:L1000__").Select  
    Application.CutCopyMode = False  
    Selection.Copy  
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _  
        :=False, Transpose:=False  
    Sheets("Check_sheet").Select  
    MsgBox "Update complete"  
End Sub`

The main thing I’m looking to achieve is to replace the code B2:L1000 with something that can assess the number of rows in column A and select a range in rows B to L accordingly.

Since column L is the last populated column, I don’t see why this can’t also be done horizontally rather than defining “B:L” incase future columns need to be added.

  • 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-05-27T10:10:05+00:00Added an answer on May 27, 2026 at 10:10 am

    Although the earlier answer has merits:

    1) I would not use COUNTA because if there are empty cells in the row or column, the cells at the bottom or the right will be ignored.

    2) I would never rely on the user picking the correct sheet to be used before running a macro; particularly one with so many sheets.

    My reaction to the question is that you have set Macro Record, wandered around your workbook and then stopped the record. You select one thing, then another. You scroll through the sheets. To me most of the statements are not clumsy they are pointless.

    The following does include an answer to your question about finding the last row of column A but it is more a tutorial about finding the dimensions of a range, getting data out of the range and then putting it somewhere else. This seems to be most of what you are trying to do with the most minimal understanding of VBA. I am sorry if this criticism is unfair but that is the impression your question gives to me.

    Sub Test()
    
      Dim RowS01Max As Integer
      Dim Sheet1Data() As Variant
    
      ' With Sheets("Sheet1") allows you to access data within worksheet Sheet1
      ' without selecting it.
      ' Range("A1:C11") refers to a range within the active sheet
      ' .Range("A1:C11") refers to a range within the sheet identified in the
      '         With statement.
      ' ^ Note the dot
      With Sheets("Sheet1")
    
        ' Rows.Count is the number of rows for the version of Excel you are using.
        ' .Cells(Rows.Count, "A") address the bottom row of column A of worksheet
        ' Sheet1.
        ' .Cells(Rows.Count, 1) refer to column A by number.
        ' End(xlUp) is the VBA equivalent of Ctrl+Up.
        ' If you positioned the cursor at the bottom of column A and pressed
        ' Ctrl+Up, the cursor would jump to the last row in column A with a value.
        ' The following statement gets that row number without actually moving
        ' the cursor.
        RowS01Max = .Cells(Rows.Count, "A").End(xlUp)
    
        ' The following statement loads the contents of range A1:C11 of
        ' Sheets("Sheet1") into array Sheet1Data.
        Sheet1Data = .Range("A1:C11").Value
    
        ' This is the same statement but the range is specified in a different way.
        ' .Cells(Row,Column) identifies a single cell within the sheet specified in
        ' the With statement.  .Cells(1,1) identifies row 1, column 1 which is A1.
        '. Cells(11, "C") identifies row 11, column C which is C11.
        Sheet1Data = .Range(.Cells(1, 1), .Cells(11, "C")).Value
    
        ' This statement uses RowS01Max to specify the last row
        Sheet1Data = .Range(.Cells(1, 1), .Cells(RowS01Max, 1)).Value
    
        ' In all three examples above, the contents of the specified range will
        ' be loaded to array Sheet1Data.  Whichever range you pick, Sheet1Data
        ' will always be a two dimensional array with the first dimension being
        ' the row and the second dimension being the column.
    
        ' In the first two examples Sheet1Data(5,3) contains the contents
        ' of cell C5.  In the third example, I have only loaded column A but the
        ' array will still has two dimensions but the only permitted value for the
        ' second dimension is 1.
    
        ' The following statement writes the contents of Sheet1Data to column "E"
    
        .Range(.Cells(1, 5), .Cells(RowS01Max, 5)).Value = Sheet1Data
    
      End With
    
      With Sheets("Sheet2")
    
        ' The following statement writes the contents of Sheet1Data to column "E"
        ' of worksheet Sheet2.
        .Range(.Cells(1, 5), .Cells(RowS01Max, 5)).Value = Sheet1Data
    
      End With
    
    End Sub
    

    Don’t despair! Most of us started with the macro recorder and still use it to discover the syntax for an unfamiliar command. Look through other questions. Some ask about exotic functionality but many are about moving data around in, to the experienced programmer, simple ways. Set up some workbooks with the questioner’s problem. Copy and paste the solution into a module. Step through it using F8 (see the debugger), switch between Excel and Editor, watch what is happening to the worksheet and move the cursor over a variable to see its current value. Spend half a day playing. You will be amazed at how quickly it starts to make sense. Good luck and good programming.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.