Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default import access data into excel

I have a data base that looks like this in access:

emp# Date Time In or out

Obviously multiple records for each employee, on each date

I would like to somehow import the data into excel though, so it looks
like this:

emp# date In Tim 1 Out tim 1 In tim 2 Out tim 2 In tim3 Out tim 3

In other words, when the date comes into excel from access, how can I
get the multiple ins and outs for a day on the same line if it's the
same date??? Do I have to write some sort of visual basic program, or
is there an easy way to do this?

I'd appreciate all suggestions

thanks,
ga

George Applegate

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default import access data into excel

George,
I think this will work for you. I didn't actually set up a database and
import data, but I did enter some data to simulate that with the Employee# in
column A, a date (formatted as a date) in column B, and in/out times
(formatted in a Time format) in columns C and D.

This code goes into a regular code module, and before running it you should
make sure that the source data imported from Access is sorted by Employee#,
Date and In-time so that the results make sense when the code runs. Rows on
the destination sheet will be based on a Name/Date match followed by all
in/out times for that date for that person.

To get the code into your Excel workbook; press [Alt]+[F11] to open the VB
Editor, choose Insert | Module and copy the code below and paste it into the
module presented to you. Make any changes needed to the sheet names defined
in the code. Import your data (if you haven't already), sort it, and then
use
Tools | Macro | Macros to select and run this macro.

Sub TransposeInOutTimes()
'list on source sheet (Sheet1) must be sorted by:
' Name then by Date then by Time In
'before running this process
Const sourceSheetName = "Sheet1" ' change if necessary
Const destSheetName = "Sheet2" ' change if necessary
Const firstNameRow = 2 ' assumes row 1 has labels
Dim sourceSheet As Worksheet
Dim empNumberList As Range
Dim anyEmpNumber As Range

Dim destSheet As Worksheet
Dim destBaseCell As Range
Dim currentEmpNumber As String
Dim currentDate As Date
Dim destRowOffset As Long
Dim destColOffset As Long

Set sourceSheet = Worksheets(sourceSheetName)
Set destSheet = Worksheets(destSheetName)
Set empNumberList = sourceSheet.Range("A" & firstNameRow & ":" _
& sourceSheet.Range("A" & Rows.Count).End(xlUp).Address)
destSheet.Cells.ClearContents ' erase old information
Set destBaseCell = destSheet.Range("A2") ' start on row 2
destRowOffset = -1 ' initialize
For Each anyEmpNumber In empNumberList
If anyEmpNumber < currentEmpNumber Then
'must begin a new row on destSheet
destRowOffset = destRowOffset + 1
currentEmpNumber = anyEmpNumber ' save this name
currentDate = anyEmpNumber.Offset(0, 1) ' get first date
destBaseCell.Offset(destRowOffset, 0) = currentEmpNumber
destBaseCell.Offset(destRowOffset, 1) = currentDate
'and get the 1st 2 In/Out times
destBaseCell.Offset(destRowOffset, 2) = anyEmpNumber.Offset(0, 2)
destBaseCell.Offset(destRowOffset, 3) = anyEmpNumber.Offset(0, 3)
destColOffset = 4 ' reset
Else
'emp# matched, check for new date
If anyEmpNumber.Offset(0, 1) < currentDate Then
'must start new row for same person
destRowOffset = destRowOffset + 1
currentDate = anyEmpNumber.Offset(0, 1) ' save date
destBaseCell.Offset(destRowOffset, 0) = currentEmpNumber
destBaseCell.Offset(destRowOffset, 1) = currentDate
'and get the 1st 2 In/Out times
destBaseCell.Offset(destRowOffset, 2) = anyEmpNumber.Offset(0, 2)
destBaseCell.Offset(destRowOffset, 3) = anyEmpNumber.Offset(0, 3)
destColOffset = 4 ' reset
Else
'same emp#, and date, just add In/Out times to the row
destBaseCell.Offset(destRowOffset, destColOffset) = _
anyEmpNumber.Offset(0, 2)
destColOffset = destColOffset + 1
destBaseCell.Offset(destRowOffset, destColOffset) = _
anyEmpNumber.Offset(0, 3)
destColOffset = destColOffset + 1
End If
End If ' end of emp# match test
Next ' move to next row on the Source Sheet
End Sub


"George Applegate" wrote:

I have a data base that looks like this in access:

emp# Date Time In or out

Obviously multiple records for each employee, on each date

I would like to somehow import the data into excel though, so it looks
like this:

emp# date In Tim 1 Out tim 1 In tim 2 Out tim 2 In tim3 Out tim 3

In other words, when the date comes into excel from access, how can I
get the multiple ins and outs for a day on the same line if it's the
same date??? Do I have to write some sort of visual basic program, or
is there an easy way to do this?

I'd appreciate all suggestions

thanks,
ga

George Applegate


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Data Import From Access Achilleas Charts and Charting in Excel 1 February 19th 07 07:26 PM
How do I import hyperlink data from Access into Excel? Dennis Excel Discussion (Misc queries) 0 February 23rd 06 03:29 PM
Import Charts and data to Access Kyriaki Charts and Charting in Excel 1 January 31st 06 07:37 PM
How to import data from a password protected Access DB into Excel. Agus Excel Discussion (Misc queries) 0 October 12th 05 05:42 PM
Excel error while trying to import data from an Access database - MSQRY32.exe has generated errors X_HOBBES Excel Discussion (Misc queries) 0 March 15th 05 06:46 PM


All times are GMT +1. The time now is 10:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"