VBA loop to transfer data to another worksheets

lplexe

New Member
Joined
Nov 17, 2020
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I'm trying to write a code that goes through sheet with raw data ("Dane") and copies case numbers (col "B") based on date (col "J") and ID (col "A"). I have worksheets named with all ID's from raw data and in these worksheets in col "A" I have the dates.

The subroutine should look through every row and match the ID with the worksheet that is named with that ID, check the date and copy the case number into that worksheet into next available column in a row that contains the date that matches with the source sheet date in col "J".

Here's what I have written (and it doesn't do a single thing):

VBA Code:
Sub Copy_to_ID_sheet()

Dim impdate As Date
Dim finalrow As Long
Dim i As Long
Dim caseno As String
Dim ID As String

finalrow = Sheets("Dane").Range("A:A").End(xlUp).Row

For i = 2 To finalrow

impdate = Sheets("Dane").Cells(i, 10)
caseno = Sheets("Dane").Cells(i, 2)
ID = Sheets("Dane").Cells(i, 1)

    If ID = Sheets(ID) Then
        EntireRow.copy Destination:=Sheets(ID).Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
    Next i
    
End Sub

Also adding screen shots of source and destination sheets
 

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,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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