VBA Loop for copying data

seadie12

New Member
Joined
Dec 23, 2021
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hi, I was looking to create a VBA where it loops down every row in a column (column G, starting in cell G3) and if that is a date I would want to copy the data from the corresponding cell in column H and paste it as a value into column F. Eg if cell G22 has a date it would copy cell H22 into F22 as a value, then carry on down the rest of the file to see if there are any more dates.

Please could some one help with this.
Thanks in advance
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi, Except date what other value can be available in Column G ? (e.g. blank cell)
 
Upvote 0
Hi,

Use below code:

VBA Code:
Sub copyData()
Dim lRow As Integer, rowno As Integer

lRow = ActiveSheet.Cells(Rows.Count, "G").End(xlUp).Row

For rowno = 3 To lRow
    If IsDate(ActiveSheet.Cells(rowno, "G")) Then
        ActiveSheet.Cells(rowno, "F") = ActiveSheet.Cells(rowno, "H")
    End If
Next
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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