VBA Count Non Blank Rows On Sheet 1 and Copy Paste Based on Counted Rows in Sheet 2

bquek

New Member
Joined
Jun 23, 2013
Messages
14
The following VBA code to count rows but it only counted one row out of 10 rows. The count starts at row 4 and cells in column A contain formula. How to modify the code to be able to count the non blank cell. Did try to replace Count with CountA but it does not work.

Code:
nrows=Worksheets("Master").Cell(Rows.Count,4).End(xlUp).Row
Worksheets ("Copy").Rows("2").copy
Worksheets ("Copy").Rows("3:"&nrows).Select
ActiveSheet.Paste

Thank you in advance for any help extended.
Cheers,
Ben
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
The value assigned to nrows is the row number of the last nonblank cell in column D on worksheet Master. What are you trying to do exactly?
 
Upvote 0
The value assigned to nrows is the row number of the last nonblank cell in column D on worksheet Master. What are you trying to do exactly?

I want to copy row 2 in Sheet 2 based on the count in Sheet 1 (Master). Sheet 1 (Master) comprise of data abstract by formulas or links starting from row 4 from column A to O (column D & E manually input). If the code counted 10 rows (column A:A) having formulas/link/data in Sheet 1 (Master), then the code should copy row 2 in Sheet 2 and paste the subsequent rows under it (9 rows). Basically Sheet 2 is arranging the combination of data from Sheet 1(Master) based on a format for data uploading into another program.
 
Last edited:
Upvote 0
Does this work for you?

Code:
Sub Test()
    nrows = Worksheets("Master").Cells(Rows.Count, 4).End(xlUp).Row - 3
    Worksheets("Copy").Rows("2").Copy Worksheets("Copy").Range("A3").Resize(nrows)
End Sub
 
Upvote 0
Does this work for you?

Code:
Sub Test()
    nrows = Worksheets("Master").Cells(Rows.Count, 4).End(xlUp).Row - 3
    Worksheets("Copy").Rows("2").Copy Worksheets("Copy").Range("A3").Resize(nrows)
End Sub

Get Run Time Error: 1004 for second row code.
 
Upvote 0
Worksheet Master Column D most of the time blank and occasionally manually input when disallowed sales tax incurred. Similarly with Column F.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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