VBA Copy Data from one sheet to another - Some cells in rows are blank and current method stops at blank cell.

Trebor200

Board Regular
Joined
Apr 21, 2015
Messages
67
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I currently use basic VBA code to select cell go down and left / right and select all data for copy.. this fails where i may have blank cells, in particular the cell i select and use selection.end down

As my data can have missing values in some cells is there a better way to select the data?

Current code below and sample data, as you can see there is some blank cells in each of the columns but i want to copy all data.

I want to copy all data from row 3..

VBA Code:
Sub CopyData ()
    Range("G3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToLeft)).Select
    Selection.Copy
End Sub

Book1
ABCDEFG
1RecordIDAccountCreated OnTypeDescrDescr 2
2
31.67E+08299030558028555912.04.2021abc1xyz1sda1
4233439368028728014.04.2021abc2xyz2sda2
51.67E+08291247928030156606.05.2021abc3xyz3sda3
61.64E+08234994668033424930.06.2021abc4xyz4sda4
71.67E+088033692106.07.2021xyz5sda5
81.67E+08301120248033893808.07.2021abc6xyz6sda6
91.68E+08306866108033926009.07.2021abc7xyz7sda7
103011069580339378abc8sda8
111.64E+08229747518034282715.07.2021abc9xyz9sda9
121.68E+08306115008034415817.07.2021abc10xyz10
131.68E+08308001158034611721.07.2021abc11xyz11sda11
141.66E+08282213458035512604.08.2021abc12xyz12sda12
151.68E+08309813118035552105.08.2021xyz13sda13
161.67E+08303895038035622106.08.2021abc14xyz14sda14
171.67E+082876568511.08.2021abc15xyz15sda15
181.68E+08306739188035947212.08.2021abc16xyz16sda16
191.65E+08257413728036565423.08.2021abc17xyz17
201.68E+08307568778037311503.09.2021abc18xyz18sda18
21310846668037405606.09.2021abc19xyz19sda19
221.67E+08303895208038345521.09.2021abc20xyz20sda20
231.68E+08306739188039088001.10.2021abc21xyz21sda21
241.68E+08310069578039148201.10.2021abc22xyz22sda22
251.68E+08311215038039173902.10.2021abc23xyz23sda23
261.67E+08298568488039489307.10.2021abc24xyz24sda24
Sheet1
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How about
VBA Code:
Sub Trebor()
   Dim UsdRws As Long
   
   UsdRws = Range("A:G").Find("*", , , , xlByRows, xlPrevious, , , False).Row
   Range("A3:G" & UsdRws).Copy
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub Trebor()
   Dim UsdRws As Long
  
   UsdRws = Range("A:G").Find("*", , , , xlByRows, xlPrevious, , , False).Row
   Range("A3:G" & UsdRws).Copy
End Sub
Perfect, Thank you...
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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