I'm creating a "Tool" with Excel with an external Database. So i'm working with 2 workbooks.
In the "Tool" workbook i have data on sheet (sheet5) that i want to save in the "Database" workbook. The data that i want to save is linked to other data in the database so i can't always add it on the first blank row.
Counting the rows of data that i want to add and insert that amount of empty rows in the database works, but the loop to copy the data from the "Tool" workbook to the "database" workbook doesn't. I always receive one or another error, most of the time it's "Run-Time Error 9 - Subscript out of range".
Set Wb = Workbooks("Database.xlsm")
Set Ws = Wb.Worksheets("Database")
Dim qty As Integer
Dim MyRange As Range
Dim MyRange2 As Range
Dim IDU As Range
Dim nr As Integer
Set MyRange = Sheet5.Range("E46:E109")
qty = Application.CountA(MyRange)
nr = 45 + qty
Set MyRange2 = Sheet5.Range("E46:E" & nr)
Range(c2.Offset(1, 0), c2.Offset(qty, 0)).EntireRow.Insert
If c2.Offset(1, 0) = "" Then Exit Do
For Each IDU In MyRange2
Set c2 = Cells(c2.Offset(1, 0).Row + 1, 0)
c2 is declared earlier in the code and is my link to the data already existing in the database where i want to save the new data under.
It's the first time that i try to create a loop so all info is welcome ;-) Thanks in advance