Import Excel File without Specific Rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lipper
    New Member
    • Mar 2010
    • 5

    Import Excel File without Specific Rows

    Is there a way to automate a process to import an excel spreadsheet without the first and last couple of rows into Access?
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    If you do it through VBA you can specify the range to import. Is it always the same rows/range you are importing?

    Comment

    • Lipper
      New Member
      • Mar 2010
      • 5

      #3
      As of now yes. I am receiving an excel file that will come in the same format periodically.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32656

        #4
        Check out the TransferSpreads heet method in the help, but the sixth parameter is Range. It will allow you to specify exactly what to include.

        Comment

        • Lipper
          New Member
          • Mar 2010
          • 5

          #5
          Thanks, I used the following code below, and it works out pretty good.
          Code:
          DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
              "Worksheet Name", "Path Name", True, "Range"
          Last edited by NeoPa; Mar 17 '10, 09:48 AM. Reason: Please use the [CODE] tags provided

          Comment

          • Lipper
            New Member
            • Mar 2010
            • 5

            #6
            Say the "Range" may change from time to time, and I was trying to find an easier way to input the cell range other than directly into the code, any ideas?

            Comment

            • TheSmileyCoder
              Recognized Expert Moderator Top Contributor
              • Dec 2009
              • 2322

              #7
              Would depend on the specific situation. One way could be to import it all, then delete the offending rows.

              Another approach could be to open an excel application via VBA (can be hidden from user), open the sheet, and programmaticall y set/check the range, provided you have something that computer logic can use to determine the range. Would have to see an example to help you with that.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32656

                #8
                Originally posted by Lipper
                Say the "Range" may change from time to time, and I was trying to find an easier way to input the cell range other than directly into the code, any ideas?
                Essentially no. There are ways around it, but they're cumbersome. This was the point of the question in post #2 of course.

                Comment

                • TheSmileyCoder
                  Recognized Expert Moderator Top Contributor
                  • Dec 2009
                  • 2322

                  #9
                  You can open the excel sheet, and make a named range, and have the transferspreads heet function always import the named range.

                  Comment

                  • Lipper
                    New Member
                    • Mar 2010
                    • 5

                    #10
                    I want to thank you both for helping me out with this. One more thought, do any of you know any method that will exclude a number of top rows as opposed to defining a range?

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32656

                      #11
                      For a Range parameter, you either need to know that the range is named, and use that, or you need to be able to specify the range in one of the standard formats, "A1:B2" or "R1C1:R2C2" . Clearly you could specify a range that missed the top X rows, but that would leave you required to specify which row to go down to too. You could mix this with an earlier suggestion, to import line X+1 to 65,536, and then delete all records with no data, but without access to the Excel file itself, and with no prior knowledge as to how many lines are there, you will not be in a position to specify a meaningful range.

                      Comment

                      Working...