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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:35:07+00:00 2026-05-25T01:35:07+00:00

I know that I can accomplish this via iterating over the first range, but

  • 0

I know that I can accomplish this via iterating over the first range, but I’m curious to see if I can accomplish it using the SpecialCells property.

Say I have a column of names with empty cells in between:

 A     B    C
Jon
Jim
Sally

Jane


Mary

If I want to use VBA to copy over just the used cells, I can say

Range("A1:A8").SpecialCells(xlCellTypeConstants, xlTextValues).Copy
Range("C1:C"&Range("A1:A8").SpecialCells(xlCellTypeConstants, xlTextValues).Count).PasteSpecial

and end up with

 A     B    C
Jon        Jon
Jim        Jim
Sally      Sally
           Jane    
Jane       Mary


Mary

Instead, I’d like to be able to do this without having to paste a range anywhere.

What I want to be able to do is have a range containing [Jon,Jim,Sally,Jane,Mary], but if I try Set rng = Range("A:A").SpecialCells(xlCellTypeConstants,xlTextValues), I either end up with the spaces as elements of the range, or using a hard-coded range of cells, with one that counts only [Jon, Jim, Sally] before it hits the space.

I’d like to be able to use the range elsewhere in the code, and I think the SpecialCells is a nice compact way of doing it, but is my only alternative to do it in a loop and compare cells as <> ""?

  • 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-25T01:35:07+00:00Added an answer on May 25, 2026 at 1:35 am

    Consider the following code:

    Dim r As Range
    Set r = Range("A:A").SpecialCells(xlCellTypeConstants, xlTextValues)
    
    Debug.Print r.Rows.Count, r.Cells.Count
    ' returns:        3            5 
    

    The only reliable piece of information in the above is r.Cells.Count. The Rows get cut at the first blank. I imagine this confuses the whole pasting process. So, you can’t paste r directly to the worksheet.

    You could transfer it to a Variant array, and then slap* that onto the sheet. But how to do this? Well, r.Cells is akin to a collection. Perhaps convert it to an array like this:

    Dim i As Long
    Dim c As Range
    Dim v As Variant
    ReDim v(1 To r.Cells.Count, 1 To 1)
    i = 0
    For Each c In r
        i = i + 1
        v(i, 1) = c
    Next c
    Range("B1").Resize(UBound(v,1),UBound(v,2)) = v
    

    No need to check for empty cells.

    You could also use Chip Pearson’s CollectionToArray procedure, which is basically a fancier implementation of the above code, maybe with a bit of modification.

    By the way, checking for <> "" will not reject cells whose value is an empty string "". If you must check for truly empty/"blank" cells, then IsEmpty is safer.

    *Credits to @Issun for coining "slap" in this context.

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

Sidebar

Related Questions

I know that I can share files using Shared Folders in Virtual PC, but
I know that you can do this easily with HQL using the following syntax:
I know that it's a subject that can raise a lot of debate, but
I know that JTable can sort by a single column. But is it possible
I know that I can insert multiple rows using a single statement, if I
Let me first state that I know next to nothing about LDAP and this
I know that can co-exists with web form no problem as Hanselman mention here
I know that I can do something like $int = (int)99; //(int) has a
I know that you can insert multiple rows at once, is there a way
I know that you can use a dummy int parameter on operator++ and operator--

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.