473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Run-Time error '1004'. Application- defined or object-defined error

Hi there

I am new to this forum so would appreciate any help that is on offer.

I am writing some VB in Excel and getting the "Run-Time error '1004'. Application- defined or object-defined error".

I have two spread sheets where I am trying to merge some data together. One spread sheet (Ad_Hoc_Test.xls) has Policy details on and the other (PA Claims Test.xls) has claims data on.

My code is basically supposed to loop through the source sheet (PA Claims Test.xls), find any matching policyID's that are also in the destination sheet (Ad_Hoc_Test.xls), then paste the row of relevant claim data next to the PolicyID data in the destination sheet.

My code loops through the source sheet fine but the first time around but then when it reaches the end of the sheet it does not go to the next Policy ID and that’s when I get the error on line -

Expand|Select|Wrap|Line Numbers
  1.  
  2. Do While arrDetails(2, 0) <> xlSheetDestination.Cells(y1, 5)
Here is the full code -

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub ImportClaims()
  3.  
  4.     Dim xlSheetSource As Worksheet
  5.     Dim xlSheetDestination As Worksheet
  6.     Dim y As Long
  7.     Dim y1 As Long
  8.     Dim x As Long
  9.     Dim policyID As String
  10.     Dim arrDetails()
  11.     Dim i As Long
  12.     Dim xlBookDestination As Workbook
  13.     Dim xlBookSource As Workbook
  14.  
  15.     Set xlBookDestination = Workbooks.Open("\\...(removed_for_question\Analysis\PA\Ad_Hoc_Test.xls")
  16.     Set xlSheetDestination = xlBookDestination.Sheets("Web")
  17.     Set xlBookSource = Workbooks.Open("\\...(removed_for_question\Analysis\PA\PA Claims Test.xls")
  18.     Set xlSheetSource = xlBookSource.Sheets("Data_Totals")
  19.  
  20.     'Row variable for xlSheetSource
  21.     y = 2
  22.  
  23.     'row variable for xlSheetDestination
  24.     y1 = 1
  25.  
  26.     'Start to loop though source file
  27.     Do While Len(xlSheetSource.Cells(y, 1)) <> 0
  28.  
  29.         policyID = xlSheetSource.Cells(y, 3)
  30.  
  31.         ReDim arrDetails(5, 0)
  32.  
  33.         x = 0
  34.         'Start looping and continue whilst on the same policy
  35.         Do While xlSheetSource.Cells(y, 3) = policyID
  36.  
  37.             ReDim Preserve arrDetails(5, x)
  38.             arrDetails(0, x) = xlSheetSource.Cells(y, 1)
  39.             arrDetails(1, x) = xlSheetSource.Cells(y, 2)
  40.             arrDetails(2, x) = xlSheetSource.Cells(y, 3)
  41.             arrDetails(3, x) = xlSheetSource.Cells(y, 4)
  42.             arrDetails(4, x) = xlSheetSource.Cells(y, 5)
  43.             arrDetails(5, x) = xlSheetSource.Cells(y, 6)
  44.  
  45.             y = y + 1
  46.             x = x + 1
  47.  
  48.         Loop
  49.  
  50.         'Loop though array to find matching policies
  51.  
  52.         Do While arrDetails(2, 0) <> xlSheetDestination.Cells(y1, 5)
  53.  
  54.         y1 = y1 + 1
  55.  
  56.         Loop
  57.  
  58.         If xlSheetDestination.Cells(y1, 5) = arrDetails(2, i) Then
  59.  
  60.                 'Insert Claim Id to destination
  61.                 xlSheetDestination.Cells(y1, 10) = arrDetails(0, 0)
  62.                 'Insert Insured to destination
  63.                 xlSheetDestination.Cells(y1, 11) = arrDetails(1, 0)
  64.                 'Insert Policy to destination
  65.                 xlSheetDestination.Cells(y1, 12) = arrDetails(2, 0)
  66.                 'Insert Assured Id to destination
  67.                 xlSheetDestination.Cells(y1, 13) = arrDetails(3, 0)
  68.                 'Insert Detail to destination
  69.                 xlSheetDestination.Cells(y1, 14) = arrDetails(4, 0)
  70.                 'Insert Total Payments to destination
  71.                 xlSheetDestination.Cells(y1, 15) = arrDetails(5, 0)
  72.  
  73.         End If
  74.  
  75.         y = y + 1
  76.  
  77.     Loop
  78.  
  79.     xlSheetDestination.Parent.Save
  80.     xlSheetSource.Parent.Close
  81.  
  82. End Sub
  83.  
Any help would be greatly appreciated.

Thanks

Matt
Oct 18 '11 #1
1 4066
Guido Geurs
767 Expert 512MB
The var "i" has no value !
If it's still not working, is it possible to attach a part of the XLS files (with some data )( fictive data if necessarily) so we can see what the structure is ?
Oct 19 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mark C | last post by:
All, I have used Excel automation many times in the past without error until now. My machine has both Access 97 and XP installed but this code is written in 97 and I am using Excel XP. The code...
2
by: dailem | last post by:
I have a bit of code tied to a command button in Access that runs a query then transfers it to a new Excel worksheet (& new file). It works fine EVERY OTHER TIME THAT I RUN IT....what the 'heck...
4
by: dkintheuk | last post by:
Hi there, I want to print a macro out to enable me to debug it and convert it to more sensible operations giving users more control. I get the error message: Application-defined or...
3
by: Maverick | last post by:
I'm new to this, but I have received so much great information here, I had to join. Here is a problem am encountering with the following code in MS Access: objSht.Activate ...
2
by: amolbehl | last post by:
I use VB6.0 and when I execute the code I have given below, I get runtime Error 1004 - Specified value is out of range. Set oXL = CreateObject("Excel.Application") oXL.Visible = True ...
4
by: ielamrani | last post by:
Hi, I am getting this error when I try to export to an excel sheet. When I click on a button to export the first time it's fine, I rename the exported excel sheet and I try to export it again and I...
0
by: grego9 | last post by:
When I run the following macro in Excel (using VBA) I get the run time error 1004 application defined or object defined error. I get the usual debug message and when I click end I actually get the...
0
by: katyg | last post by:
I have recently upgraded from Excel 2000 to 2007. I have always been able to record macros to use in any workbook without an issue. No matter what I do, I can not seem to get a simple recorded...
5
by: titli | last post by:
Hi guys, I have a .mdb which generates , further some mini .mdbs..Later these generated mini mdbs are provided as input to excel viewer.Till yesterday everything was working fine.. But today after...
0
by: Art Altman | last post by:
I have found a workaround to the Excel VBA “ run time error 40036 application-defined or object error”. It does not fix the original problem, which is in excel, SOMEWHERE. A few responses I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.