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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,234
Messages
6,123,776
Members
449,123
Latest member
StorageQueen24

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