Macros to copy new data

RainMan21

New Member
Joined
Jan 29, 2020
Messages
1
Office Version
2016
Platform
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
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,089,576
Messages
5,409,097
Members
403,251
Latest member
BAMORAN

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top