I would like to search a reporting spreadsheet(A) for a date and then search for that date in a data source spreadsheet(B). Once found, I would like to copy and paste data (from the same row as the date) into the corresponding date in the reporting spreadsheet(A).
Some conditions:
- Once used, data from the data source spreadsheet (B) cannot be reused and therefore I want to search for the next row with the same date...
- this is the reason I am using a macro (otherwise I would just use a vlookup)
I am new to VBA so I have been trying to use some loops in combination but I am unsuccessful
I want to know if there is a simpler way to do it?
Sub DataToRegister()
Dim Row As Double 'row is the row variable for the destination spreadsheet
Dim i As Double
Dim x As Integer 'x is the row variable for the source spreadsheet
For Row = 1 To 825
i = Sheets("Register Data Fields").Cells(Row, 1)
While i <> DateSerial(1900, 1, 0)
'DateSerial(1900, 1, 0) --> this is the default for no data in the field, i.e. i want to skip these
For x = 1 To 825
If Sheets("HANSON DATA").Cells(x, 2) = Sheets("Register Data Fields").Cells(Row, 1) Then
Sheets("HANSON DATA").Select
Cells(x, 1).Select
Selection.Copy
Sheets("Register Data Fields").Select
Cells(Row, 22).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Next
Next
Wend
End If
End Sub
Errors that I am getting include:
Next
withoutfor
x2wend
withoutwhile
i
mismatch variable type