Macros to copy new data

RainMan21

New Member
Joined
Jan 29, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi, I'm trying to compose a code in which I'm copying new values from Sheet3 (in code I select range by hand), but I'd like excel to keep track of which rows are new. Now I select values from Sheet3 column A based on if value from same row's D column is equal to Sheet2 B column value. Also I need to do such copying with every 16th blank cell from Sheet2 column H. Here's what I've composed so far:

Sub randomize()
Application.ScreenUpdating = False

Dim RNG1 As Range, RNG2 As Range, r As Range, p As Range, d As Collection, N As Long

Set RNG1 = Application.InputBox(Prompt:="Select Range", Type:=8)
Set RNG1 = Sheet3.Range("A1:A65536")
Set RNG2 = Sheet2.Range("B2:B12")

For Each p In RNG2
Set d = New Collection
For Each r In RNG1
If Sheet3.Cells(r.Row, 1).Value <> vbNullString And p.Value <> vbNullString And Sheet3.Cells(r.Row, 4).Value = p.Value Then
d.Add r
N = Application.WorksheetFunction.RandBetween(1, d.Count)
Set rselect = d.Item(N)
rselect.Copy
Sheet2.Cells(p.Row, 8).PasteSpecial Paste:=xlPasteValues
End If
Next r
Set d = Nothing
Next p

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,216,342
Messages
6,130,114
Members
449,558
Latest member
andyamcconnell

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