Results 1 to 5 of 5

Define:Run-time error '1004'

Threaded View

  1. #1
    Registered User
    Join Date
    07-07-2006
    Posts
    4

    Define:Run-time error '1004'

    When I run my code every thing works ok, but it got error when the row number went up to 257 at the second red line. The error message is Run-time error '1004' Application-defined or object-defined error. I have value in cell A257 just like any other A cells. Nothing really funcy.

    rw(1) = 512
    rw(2) = 408
    Worksheets(wSheet(1)) = "template1'
    Worksheets(wSheet(2)) = "template2"

    Any one can help me on this?
    Thanks a million.

    John

    Here is the code:
     
      subDir = GetDirectory("Please select a folder you like to save your result.")
      fol = subDir + "_Comparesion_" + startdate + "\" ' change to match the folder path
    
    'Find Sub directories for different cubs.
      strDir = Dir(ActiveWorkbook.Path & "\", vbDirectory)
      ii = 0
      ControlFile = ActiveWorkbook.Name
    Do Until strDir = ""
      strDir = Dir
        'Find current Alphablox file.
        If InStr(1, strDir, "Alphablox_Volume") > 0 And InStr(strDir, CStr(startdate)) > 0 Then
         AlphabloxFileName = strDir
         Dir_array(0) = AlphabloxFileName
        End If
        'Find current EDW file.
        If InStr(strDir, "EDW_Volume") > 0 And InStr(strDir, CStr(startdate)) > 0 Then
         EdwFileName = strDir
         Dir_array(1) = EdwFileName
        End If
    Loop
       If AlphabloxFileName = "" Then
        MsgBox ("Alphablox file for today is not in the directory!")
        Exit Sub
       End If
       If EdwFileName = "" Then
        MsgBox ("EDW file for today is not in the directory!")
        Exit Sub
       End If
    ' Create res.txt file for each cub
    jj = 0
    Do Until jj = 2
     jjj = jj + 1
     wSheet(jjj) = "Template" & jjj
     Windows(ControlFile).Activate
     Worksheets(wSheet(jjj)).Activate
     Cur_Dir = ActiveWorkbook.Path & "\" & Dir_array(jj)
    
     Workbooks.Open (Cur_Dir)
     ActiveSheet.Name = "Sheet1"
     ActiveSheet.Range("A1").Select
     Selection.EntireRow.Insert
     ActiveSheet.Columns("A:BZ").Select
     Selection.Copy
     Windows(ControlFile).Activate
     Worksheets(wSheet(jjj)).Activate
     ActiveSheet.Range("A1").Select
     ActiveSheet.Paste
     Application.CutCopyMode = False 'Clear Clipboard
     Windows(Dir_array(jj)).Activate
     ActiveWorkbook.Close SaveChanges:=False
     Windows(ControlFile).Activate
     Worksheets(wSheet(jjj)).Activate
    
        rw(jjj) = ActiveSheet.UsedRange.Rows.Count
        cl(jjj) = ActiveSheet.UsedRange.Columns.Count
        jj = jj + 1
    
    'Insert Columns
    If jjj = 1 Then
     For cl1 = 1 To cl(jjj)
     ActiveSheet.Range("B1").Select
     If cl1 = 1 Then
      ActiveCell.EntireColumn.Offset(0, cl1).Insert
      ActiveCell.EntireColumn.Offset(0, cl1).Insert
      Else
      ActiveCell.EntireColumn.Offset(0, 3 * (cl1 - 1) + 1).Insert
      ActiveCell.EntireColumn.Offset(0, 3 * (cl1 - 1) + 1).Insert
      End If
     Next cl1
    End If
    Loop
    
    Worksheets(wSheet(1)).Activate
    cl(1) = ActiveSheet.UsedRange.Columns.Count
    
    'Copy EDW values to template sheet 1
     For i = 8 To rw(1)
      ActiveSheet.Range("a" & i).Select
      va1 = Replace(ActiveCell.Value, "*", "")
    
      For j = 6 To rw(2)
       Worksheets(wSheet(2)).Activate
       With Worksheets(wSheet(2)).Cells(1, j)
        ActiveSheet.Range("a" & j).Select
        va2 = Trim(ActiveCell.Value)
        If va1 = va2 Then
        ii1 = 1
        cll = Round(cl(jjj) / 2, 0)
         For cl1 = 1 To cll
           Worksheets(wSheet(1)).Cells(i, 3 * (ii1 * 2 - 1)).Value = Worksheets(wSheet(2)).Cells(j, ii1 * 2 + 1).Value
           Worksheets(wSheet(1)).Cells(i, 3 * (ii1 * 2 - 1) + 3).Value = Worksheets(wSheet(2)).Cells(j, ii1 * 2 + 2).Value
    
           ii1 = ii1 + 1
         Next cl1
        End If
       End With
      Next j
     Next i
      
    MsgBox ("Here")
    Last edited by Johnyue; 01-02-2007 at 08:45 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1