VBA to count number of new rows and add date in adjacent column

hb_123

New Member
Joined
Apr 4, 2012
Messages
11
Hi there, I'm quite new to VBA so any help is appreciated!! :rolleyes:

I have a macro that opens Workbook A, copies the data and pastes it in Workbook B.(Sheet 1) below existing data.
What i would like to do is have a code that can count the number of rows that have been added and paste the date (which located in Sheet1 cell E2) in column D.

So for example, in the below, i would like the VBA to count the last three rows (newly pasted below existing data), and paste in the date from E2 into the the blank rows.

City
Country
Rainfall
Date
London
UK
5049
02/05/2017
Manchester
UK
900
02/05/2017
London
UK
690


Manchester
UK
500


New York
USA
594



<tbody>
</tbody>


Any help at all would be very very welcome!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi hb_123 You might try the code below.

Code:
Sub hb_123_copy_date()
Dim i As Integer
i = 1
    While Cells(i, 1).Value <> ""
        If Cells(i, 4).Value = "" Then
'Copies contents of E2 to empty cell in column D
            Cells(i, 4).Value = Cells(2, 5).Value
            
        End If
    i = i + 1
    Wend
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,630
Members
449,041
Latest member
Postman24

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