none
VBA - Run Time Error 1004 'Application Defined or Object Defined Error' RRS feed

  • Question

  • Below is the error I am facing after selecting the Map Target button and it is occuring for DK30_USA_ICV3.xlsx file.

    Run Time Error 1004 'Application Defined or Object Defined Error'

    Code-->

    Dim colyear As Integer
    colyear = 1
    'Do Until Left(wb.Sheets("IC - Sales Forecast").Cells(9, colyear).Value, 3) = "12."
    Do Until wb.Sheets("IC - Sales Forecast").Cells(10, coltemp).Value = ""
    If wb.Sheets("IC - Sales Forecast").Cells(9, coltemp).Value <> "" And wb.Sheets("IC - Sales Forecast").Cells(10, coltemp).Value = "Sales forecast" Then
    Do Until wb.Sheets("IC - Sales Forecast").Cells(myrowsource, 1).Value = ""
    ThisWorkbook.Worksheets("Target").Cells(myrowtarget, 1).Value = wb.Sheets("IC - Sales Forecast").Range("C5").Value  (Error occuring in this line)
    ThisWorkbook.Worksheets("Target").Cells(myrowtarget, 2).Value = wb.Sheets("IC - Sales Forecast").Range("C6").Value
    ThisWorkbook.Worksheets("Target").Cells(myrowtarget, 3).Value = wb.Sheets("IC - Sales Forecast").Range("C7").Value
    ThisWorkbook.Worksheets("Target").Cells(myrowtarget, 4).Value = wb.Sheets("IC - Sales Forecast").Cells(myrowsource, 1).Value
    ThisWorkbook.Worksheets("Target").Cells(myrowtarget, 5).Value = "'" & wb.Sheets("IC - Sales Forecast").Cells(myrowsource, 3).Value
    ThisWorkbook.Worksheets("Target").Cells(myrowtarget, 6).Value = Right(wb.Sheets("IC - Sales Forecast").Cells(9, coltemp).Value, 4)
    ThisWorkbook.Worksheets("Target").Cells(myrowtarget, 7).Value = Left(wb.Sheets("IC - Sales Forecast").Cells(9, coltemp).Value, 2) & Right(wb.Sheets("IC - Sales Forecast").Cells(9, coltemp).Value, 4)
    ThisWorkbook.Worksheets("Target").Cells(myrowtarget, 8).Value = wb.Sheets("IC - Sales Forecast").Cells(myrowsource, coltemp).Value
    ThisWorkbook.Worksheets("Target").Cells(myrowtarget, 16).Value = "PC"
    ThisWorkbook.Worksheets("Target").Cells(myrowtarget, 17).Value = "EUR"

    Sunday, March 22, 2015 11:00 AM

All replies

  • Re: error 1004

    Declare and define all variables.
    Sunday, March 22, 2015 2:21 PM
  • As Jim said. Looks like myrowtarget has not been declared or setup. If it has but not in the code you sent, the name for either sheet is possibly wrong.

    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Sunday, March 22, 2015 8:50 PM
  • Hi Gill,

    Thank you very much for the response.

    Sorry I have not attach the declaration part of the variable myrowtarget.Below is the same

    Sub ForecastUpload()

    Dim myrowsource, myrowtarget, mycolsource As Integer
    myrowsource = 12
    ''mycolsource = 1
    myrowtarget = 3

    Let me give a brief about the issue which i am facining. I have a marco which is reading below four templates from the folder created in c drive.

    1-->DK30_Japan_ICV2

    2-->DK30_Korea_ICV2

    3-->DK30_Taiwan_ICV2

    4-->DK30_US_ICV3

    Once the marco read the files i am trying to map them using a button "Map Tareget".The first three files are mapping properly but when it is coming to last file (US) one i am getting the run time error.The surprise thing is this is happening only when I am mapping four files together.When i am trying to map only US one it is working fine.

    Regards

    Jay


    Monday, March 23, 2015 8:18 AM