VBA Only Copying to First Cell After a Blank Cell

BrittKnee

Board Regular
Joined
Dec 4, 2017
Messages
82
Hi! I am hitting a snag in a macro I have written where certain fields are being copied and pasted into a new tab. The code works fine if there are no blank cells in the field, but if there are it will only copy to the first record after the blank cell. For instance, if the first cell after the header is blank and the 2nd is not, then it will copy and first cell (blank) and the second cell, but will not continue the selection to the rest of the field. Below is a sample of the code I am using. I'm sure this is any easy fix, but I just can't figure it out. Any and all help is appreciated

Code:
Range("Table1[[#Headers],[CUST_REF_NUM4]]").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    ws2.Select
    Range("A1").Select
    ActiveSheet.Paste
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try replacing all that code with
VBA Code:
Range("Table1[CUST_REF_NUM4]").Copy ws2.Range("A1")
 
Upvote 0
Thanks! This worked, except it didn't copy the header. This works, but is there a cleaner way to code it?

Code:
Range("Table1[[#Headers],[CUST_REF_NUM4]]").Copy 
ws2.Range("A1")
Range("Table1[CUST_REF_NUM4]").Copy 
ws2.Range("A2")
 
Last edited:
Upvote 0
How about
VBA Code:
Range("Table1[[#All],[CUST_REF_NUM4]]").Copy ws2.Range("A1")
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,884
Messages
6,127,558
Members
449,385
Latest member
KMGLarson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top