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 7761503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:09:09+00:00 2026-06-01T14:09:09+00:00

How do I modify this line in VBA to only select the columns that

  • 0

How do I modify this line in VBA to only select the columns that have values?

Set rng = Range("A1", Range("A65536").End(xlUp)).SpecialCells(xlCellTypeVisible)

I don’t think I’m doing something right since the CountLarge property is several billion cells

Here is a sample of my data

enter image description here

  • 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-01T14:09:10+00:00Added an answer on June 1, 2026 at 2:09 pm

    @SiddharthRout Yes I only need the rows that have data. I think I have it working now with End(xlToLeft) from @JMax … Now that I’m iterating over the cells, I can just quit the For each loop once the last row is reached. I might have this working now. – makerofthings7 14 mins ago

    For this neither you need .SpecialCells nor do you need to loop through the rows 🙂

    Here is a sample code. This will copy all the rows which have data to Sheet2 (TRIED AND TESTED)

    Sub Sample()
        Dim ws As Worksheet
        Dim rng As Range
        Dim LastRow As Long, LastCol As Long
    
        Set ws = Sheets("Sheet1")
    
        With ws
            LastRow = .Cells.Find(What:="*", After:=.Range("A1"), Lookat:=xlPart, _
            LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
    
            LastCol = .Cells.Find(What:="*", After:=.Range("A1"), Lookat:=xlPart, _
            LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, _
            MatchCase:=False).Column
    
            With .Range("A1:" & Split(Cells(, LastCol).Address, "$")(1) & LastRow)
                .AutoFilter Field:=1, Criteria1:="<>"
                Set rng = ws.AutoFilter.Range
                rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
                Destination:=Sheets("Sheet2").Range("A1")
            End With
        End With
    End Sub
    

    SNAPSHOT

    enter image description here

    I am assuming that all cells in a particular row will have data and there won’t be a case like this

    @makerofthings7: I think I know what exactly you are trying to do 🙂 you don’t need to use loops to achieve what you want. Just a quick question. Is it possible that say Cell C10 might have a value but B10 might not? – Siddharth Rout 12 mins ago

    If there is then we will have to set the autofilter criteria accordingly.

    Edit:
    WAY 2

    The other way would be to sort your data, pushing the blanks way down and then copying the resulting range 🙂

    HTH

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

Sidebar

Related Questions

How can I modify this: /services/type/single_dwelling/ to this: /ajax/services/single_dwelling/development Currently I have: linkUrl =
How do I modify this MySQL query to only count leadIDs from table leads
I found this PHP code in an app I have to modify... $links =
I have this line /Od /D WIN32 /D _DEBUG /FD /EHa /MDd /FoDebug /FdDebug\vc80.pdb
I have written a generic class class MyClass : MyClass<string> { } //this line
How do I modify this regex so that 0 isn't matched, but the number
So I have this line in my php form processor: $automessage = 'Thanks for
I have a dozen or so Perl files with this line: my $version =
I have a line of code in JavaScript, using prototype, that is run several
I've inherited some VBA code (non-.NET, Excel 2003) I have to modify. I want

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.