Results 1 to 5 of 5

Sheet import macro stopped working.

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Sheet import macro stopped working.

    Hello, I have been using this macro succesfuly for some time now and today it decided to not work. Can someone help me troubleshoot it?

    It fails on this line:
    Set RngEnd = SrcWks.Cells(Rows.Count, SrcRng.Column).End
    Sub ImportData()
    
      Dim Data As Variant
      Dim DstRng As Range
      Dim DstWks As Worksheet
      Dim myFilter As String
      Dim N As Long
      Dim R As Long
      Dim RngEnd As Range
      Dim SrcRng As Range
      Dim SrcWks As Worksheet
      Dim SrcWkb As Workbook
      Dim WkbName As String
      
        Set DstWks = ThisWorkbook.Worksheets("Complaints db")
        Set DstRng = DstWks.Range("A3:U3")
        Set RngEnd = DstWks.Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False)
        
        N = IIf(RngEnd.Row < DstRng.Row, 1, RngEnd.Row - 1)
        
        myFilter = "Excel Workbooks (*.xls;*.xlsm),*.xls;*.xlsm"
        
        WkbName = Application.GetOpenFilename(myFilter)
        If WkbName = "False" Then Exit Sub
        
          Set xlApp = CreateObject("Excel.Application")
          xlApp.WindowState = xlMinimized
          Set SrcWkb = xlApp.Workbooks.Open(WkbName)
          
            UserForm1.Show
          
            Set SrcWks = SrcWkb.ActiveSheet
            
            Set SrcRng = SrcWks.Range("A3:K3")
            Set RngEnd = SrcWks.Cells(Rows.Count, SrcRng.Column).End(xlUp)
            Set SrcRng = IIf(RngEnd.Row < SrcRng.Row, SrcRng.Row, SrcWks.Range(SrcRng, RngEnd))
            
              Data = Array("G", "I", "M", "D", "O", "J", "N", "R", "Q", "A")
              
              For R = 1 To SrcRng.Rows.Count
              
                DstRng.Cells(N, Data(0)) = SrcRng.Cells(R, 1)
                DstRng.Cells(N, Data(1)) = SrcRng.Cells(R, 2)
                DstRng.Cells(N, Data(2)) = SrcRng.Cells(R, 3)
                DstRng.Cells(N, Data(3)) = SrcRng.Cells(R, 5)
                'DstRng.Cells(N, Data(4)) = SrcRng.Cells(R, 6)
                DstRng.Cells(N, Data(4)) = SrcRng.Cells(R, 7)
                DstRng.Cells(N, Data(5)) = SrcRng.Cells(R, 8)
                DstRng.Cells(N, Data(6)) = SrcRng.Cells(R, 9)
                DstRng.Cells(N, Data(7)) = SrcRng.Cells(R, 10)
                DstRng.Cells(N, Data(8)) = SrcRng.Cells(R, 11)
                DstRng.Cells(N, Data(9)) = "PIR"
                N = N + 1
              Next R
            
        SrcWkb.Close False
        xlApp.Quit
        Set xlApp = Nothing
        Columns("G:G").Select
        Selection.NumberFormat = "m/d/yyyy"
        
    End Sub
    I have included the workbook that contains the macro and a sample import workbook.

    Here is the link to the original thread:
    http://www.excelforum.com/excel-prog...readsheet.html

    Thanks for any help you may be able to provide!
    Attached Files Attached Files
    Last edited by dcgrove; 05-12-2010 at 04:22 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