Copy records until null

MC09

New Member
Joined
Jun 11, 2008
Messages
6
Hi,

I used this code to copy all the records from column A. But I need a code that will copy the records until the next row is null. Please help. Thanks in advance.


With Sheets("Sheet2")
.Range(.Range("A1"), .Range("A65536").End(xlUp)).Copy
End With
Sheets("Test").[A65536].End(xlUp)(2).PasteSpecial Paste:=xlValues

Example:
1 AA
2 BB
3 CC
4
5 DD
6 EE
7 FF

* copy 1-3
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

schielrn

Well-known Member
Joined
Apr 4, 2007
Messages
6,941
Try:

Code:
With Sheets("Sheet2")
.Range(.Range("A1"), .Range("A1").End(xldown)).Copy
End With
Sheets("Test").[A65536].End(xlUp)(2).PasteSpecial Paste:=xlValues
Hope that helps.
 
Upvote 0

MC09

New Member
Joined
Jun 11, 2008
Messages
6
Thanks for the reply. Btw, I used this code....

Do While ActiveCell <> ""
counter = counter + 1
ActiveCell.Offset(1, 0).Activate
wksTest.Cells(9 + counter, 2) = ActiveCell.Value
wksTest.Cells(9 + counter, 3) = ActiveCell.Offset(0, 2).Value
wksTest.Cells(9 + counter, 4) = ActiveCell.Offset(0, 4).Value
Loop
 
Upvote 0

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi, MCO9,
WELCOME to the Board!!!

Your code might be working, but consider that "activating" cells will slow down the process. Also the "loop" is not needed. So take a look at schielrns suggestion.

kind regards,
Erik
 
Upvote 0

MC09

New Member
Joined
Jun 11, 2008
Messages
6
Hi Erick,

Yup, actually the code is a little slow. But I also need to find a certain word wherein I will start copying and end before the null. Then look again for that word and so on.

Code:
Do While ActiveCell.Value <> "Main number"
        ActiveCell.Offset(1, 0).Select
    Loop
 
    myRow1 = ActiveCell.Row
    ActiveCell.Offset(2, 0).Activate
 
    Do While ActiveCell <> ""
        counter = counter + 1
        wksTest.Cells(counter2 + 9 + counter, 2) = ActiveCell.Value
        wksTest.Cells(counter2 + 9 + counter, 3) = ActiveCell.Offset(0, 2).Value
        wksTest.Cells(counter2 + 9 + counter, 4) = ActiveCell.Offset(0, 4).Value
        ActiveCell.Offset(1, 0).Activate
    Loop
 
Upvote 0

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
you got my tip, if you want to persist and still use "activate" your code will always be slow

to find something in a range, just use the tool designed for that
FIND, method
check out the VBA helpfiles
 
Upvote 0

Forum statistics

Threads
1,191,691
Messages
5,988,111
Members
440,126
Latest member
duque00

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
Top