Results 1 to 6 of 6
  1. #1
    Kaloyanides is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Location
    Arlington, MA
    Posts
    51

    Importing Data from Excel - Transpose - Lots of Data


    Good Morning!

    I'm looking for help importing data into Access from Excel

    I have:

    ITEM# PRODUCTNAME DATE1 DATE2 DATE3 DATE4 DATE5 DATE6 DATE7 ETC...
    001 NAME1 COST1 COST2 COST3 COST4 COST5 ETC...
    002 NAME2 COST1 COST2 COST3 COST4 COST5 ETC...

    I have about 1,000 items and about 60 columns with a date in the column heading and then the recorded cost for each item below.

    I need to get this into Access so that every item and all dates/costs associated with each item listed so the data can be displayed in a continuous form attached to each item master record.

    Hopefully this makes sense and there is someone that can help! Otherwise, I lose the data or spend countless hours copying and pasting.

    Thanks!

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    IMO, the easiest thing to do is to create an Excel macro that cleans up the data for you, and saves the file.
    Then, import that cleaned up file into your Access table.

    If you need help doing that, if you can provide a small actual detailed example of what the data currently looks like, and what it needs to look like to import into Access, I can help you with that Excel macro.
    Be sure to indicate what columns that data is in in Excel, and what row the data starts on.

  3. #3
    Kaloyanides is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Location
    Arlington, MA
    Posts
    51
    That would be great if you could help. Beyond my abilities. The item number goes across the top and the dates go down. This is a sample of items and dates. I also have it the other way with the items going down and the dates going across the top. Not sure if it makes a difference. I was playing trying to find a way to get into access. Thanks!

    ITEMNO 1000 1001 1002 1003 1004 1005 1006
    PRODUCT 1/2" Crinkle Cut French Fries 3/8" Clear Coat French Fries 3/8" Seasoned Fries 3/8" Straight Fries 3/8" Thin Cut French Fries Golden Patties Coated Fries NP
    18-Apr
    17-Apr
    15-Apr
    14-Apr
    13-Apr
    12-Apr $25.11 $29.14 $26.95 $18.50
    11-Apr $37.68
    10-Apr
    8-Apr
    7-Apr
    4/6
    4/5 $25.11 $29.14 $16.15 $18.50
    4/4 $25.11 $29.14 $16.15 $18.50
    4/3 $25.11 $29.14 $16.15 $18.50
    3/24 $25.11 $29.14 $16.15 $18.50
    2/8 $25.11 $29.14 $16.15 $18.50
    2/7 $25.11 $29.14 $16.15 $18.50

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Here is Excel VBA code to clean up your data.
    It takes the data from Sheet1, and pastes it to Sheet2 in the cleaned up format. You may need to change the sheet name references.
    Code:
    Sub MyCopy()
    
        Dim srcWS As Worksheet
        Dim destWS As Worksheet
        Dim lastRow As Long
        Dim lastCol As Long
        Dim myRow As Long
        Dim myCol As Long
        Dim destRow As Long
        
        Application.ScreenUpdating = False
        
    '   Set source and destination worksheets
        Set srcWS = Sheets("Sheet1")
        Set destWS = Sheets("Sheet2")
        
    '   Pre-populate headers on destination sheet
        destWS.Range("A1") = "ITEMNO"
        destWS.Range("B1") = "PRODUCT"
        destWS.Range("C1") = "DATE"
        destWS.Range("D1") = "PRICE"
        destRow = 1
        
    '   Find last row/column with data on source sheet
        lastRow = srcWS.Cells(Rows.Count, "A").End(xlUp).Row
        lastCol = srcWS.Cells(1, Columns.Count).End(xlToLeft).Column
        
    '   Loop through all columns starting in column 2
        For myCol = 2 To lastCol
    '       Loop through all rows starting in row 3
            For myRow = 3 To lastRow
    '           Check to see if there is a price, if so copy to destination sheet
                If srcWS.Cells(myRow, myCol) > 0 Then
                    destRow = destRow + 1
                    destWS.Cells(destRow, "A") = srcWS.Cells(1, myCol)
                    destWS.Cells(destRow, "B") = srcWS.Cells(2, myCol)
                    destWS.Cells(destRow, "C") = srcWS.Cells(myRow, "A")
                    destWS.Cells(destRow, "D") = srcWS.Cells(myRow, myCol)
                End If
            Next myRow
        Next myCol
    
    '   Format date column on destination sheet
        destWS.Columns("C:C").NumberFormat = "m/d/yyyy"
        
        Application.ScreenUpdating = True
        
    End Sub

  5. #5
    Kaloyanides is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Location
    Arlington, MA
    Posts
    51

    You are amazing!!! Wow!!!

    Exactly what I needed!!! Thanks a million!!!


    Quote Originally Posted by JoeM View Post
    Here is Excel VBA code to clean up your data.
    It takes the data from Sheet1, and pastes it to Sheet2 in the cleaned up format. You may need to change the sheet name references.
    Code:
    Sub MyCopy()
    
        Dim srcWS As Worksheet
        Dim destWS As Worksheet
        Dim lastRow As Long
        Dim lastCol As Long
        Dim myRow As Long
        Dim myCol As Long
        Dim destRow As Long
        
        Application.ScreenUpdating = False
        
    '   Set source and destination worksheets
        Set srcWS = Sheets("Sheet1")
        Set destWS = Sheets("Sheet2")
        
    '   Pre-populate headers on destination sheet
        destWS.Range("A1") = "ITEMNO"
        destWS.Range("B1") = "PRODUCT"
        destWS.Range("C1") = "DATE"
        destWS.Range("D1") = "PRICE"
        destRow = 1
        
    '   Find last row/column with data on source sheet
        lastRow = srcWS.Cells(Rows.Count, "A").End(xlUp).Row
        lastCol = srcWS.Cells(1, Columns.Count).End(xlToLeft).Column
        
    '   Loop through all columns starting in column 2
        For myCol = 2 To lastCol
    '       Loop through all rows starting in row 3
            For myRow = 3 To lastRow
    '           Check to see if there is a price, if so copy to destination sheet
                If srcWS.Cells(myRow, myCol) > 0 Then
                    destRow = destRow + 1
                    destWS.Cells(destRow, "A") = srcWS.Cells(1, myCol)
                    destWS.Cells(destRow, "B") = srcWS.Cells(2, myCol)
                    destWS.Cells(destRow, "C") = srcWS.Cells(myRow, "A")
                    destWS.Cells(destRow, "D") = srcWS.Cells(myRow, myCol)
                End If
            Next myRow
        Next myCol
    
    '   Format date column on destination sheet
        destWS.Columns("C:C").NumberFormat = "m/d/yyyy"
        
        Application.ScreenUpdating = True
        
    End Sub

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Importing data from Excel, does not import all data
    By mommyof4kids in forum Import/Export Data
    Replies: 5
    Last Post: 08-25-2016, 08:54 AM
  2. Formstack & Importing Data via excel, best way to collect data?
    By Yogibear in forum Import/Export Data
    Replies: 2
    Last Post: 02-10-2014, 07:05 PM
  3. Importing data from Excel
    By nik9 in forum Import/Export Data
    Replies: 2
    Last Post: 10-12-2012, 02:36 PM
  4. Importing data from Excel
    By dsaxena15 in forum Access
    Replies: 1
    Last Post: 10-03-2012, 10:56 AM
  5. Importing data from excel:
    By Mclaren in forum Programming
    Replies: 5
    Last Post: 04-30-2012, 01:19 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums