PC Review


Reply
Thread Tools Rate Thread

Database function - convert flat table

 
 
Arjen de Winter
Guest
Posts: n/a
 
      22nd Sep 2006
Hi All,

I'm linking a worksheet to a table on a website on Internet. The data on
the table is in the following format:

LETTER NUMBER COLOR
Alpha One Green
Alpha Two Purple
Bravo Two Orange
Delta Seven Green
Delta One Nine
Etc.


The format I need is the following:

NUMBER One Two Three Four Five Six Seven
LETTER
Alpha Green Purple
Bravo Orange
Charlie
Delta Green
Echo Nine
Etc.


So:
The first column in the old table should become row headers (records)
The second column should become column headers (fields)
The third column should become the data


I thought I'd be able to do that with Pivot tables, but that just allows
you to summarize, count, etc.

I know that the information in the table is unique. E.g. there is no
instance where data in a record's field would be filled twice.

It's easy enough to import the table into Access, analyze it, and then
move it to Excel. However, I want to have a permanent link with the data
so that I can instantaneously refresh the information (and the results
of the analysis of that information).

Thanks,


Arjen
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      22nd Sep 2006
Arjen,

You can use a macro - select a single cell in your table, then run the macro below.

OR ----

If you have a set number of Letter and Number values, then you could set up a table made up of
formulas.

With your example database in cells A1:C6 on a sheet named DataBase, and your row and column headers
in row 1 and column A of a sheet named CrossTab, in cell B2, array enter (enter using
Ctrl-Shift-Enter) this formula

=IF(SUM((DataBase!$A$1:$A$6='CrossTab'!$A2)*(DataBase!$B$1:$B$6='CrossTab'!B$1)*ROW(DataBase!$B$1:$B$6))=0,"",INDEX(DataBase!$C$1:$C$6,SUM((DataBase!$A$1:$A$6='CrossTab'!$A2)*(DataBase!$B$1:$B$6='CrossTab'!B$1)*ROW(DataBase!$B$1:$B$6))))

And then copy to B24 (which is what your example would produce)....

HTH,
Bernie
MS Excel MVP

Sub DBtoCrossTab2()
Dim myCell As Range
Dim myTable As Range
Dim mySht As Worksheet
Dim myRow As Long
Dim myCol As Integer

Set myTable = ActiveCell.CurrentRegion

If myTable.Columns.Count <> 3 Then
MsgBox "This macro works on a 3 column database only"
Exit Sub
End If

On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Cross Tab").Delete
Application.DisplayAlerts = True

Set mySht = Worksheets.Add
mySht.Name = "Cross Tab"

'myTable.Rows(1).EntireRow.Copy mySht.Rows(1)

Set myTable = myTable.Offset(1, 0).Resize _
(myTable.Rows.Count - 1, myTable.Columns.Count)

For Each myCell In myTable.Columns(1).Cells
If IsError(Application.Match(myCell.Value, _
mySht.Range("A:A"), False)) Then
mySht.Range("A65536").End(xlUp)(2).Value = myCell.Value
End If
If IsError(Application.Match(myCell(1, 2).Value, _
mySht.Range("1:1"), False)) Then
mySht.Range("IV1").End(xlToLeft)(1, 2).Value = myCell(1, 2).Value
End If

myRow = Application.Match(myCell.Value, _
mySht.Range("A:A"), False)
myCol = Application.Match(myCell(1, 2).Value, _
mySht.Range("1:1"), False)

mySht.Cells(myRow, myCol).Value = myCell(1, 3).Value

Next myCell

End Sub


"Arjen de Winter" <(E-Mail Removed)> wrote in message
news:4513fa6b$0$4512$(E-Mail Removed)...
> Hi All,
>
> I'm linking a worksheet to a table on a website on Internet. The data on the table is in the
> following format:
>
> LETTER NUMBER COLOR
> Alpha One Green
> Alpha Two Purple
> Bravo Two Orange
> Delta Seven Green
> Delta One Nine
> Etc.
>
>
> The format I need is the following:
>
> NUMBER One Two Three Four Five Six Seven
> LETTER
> Alpha Green Purple
> Bravo Orange
> Charlie
> Delta Green
> Echo Nine
> Etc.
>
>
> So:
> The first column in the old table should become row headers (records)
> The second column should become column headers (fields)
> The third column should become the data
>
>
> I thought I'd be able to do that with Pivot tables, but that just allows you to summarize, count,
> etc.
>
> I know that the information in the table is unique. E.g. there is no instance where data in a
> record's field would be filled twice.
>
> It's easy enough to import the table into Access, analyze it, and then move it to Excel. However,
> I want to have a permanent link with the data so that I can instantaneously refresh the
> information (and the results of the analysis of that information).
>
> Thanks,
>
>
> Arjen



 
Reply With Quote
 
Arjen de Winter
Guest
Posts: n/a
 
      22nd Sep 2006
Hi Bernie,

This is fantastic. Thank you so much! I do indeed have a set number of
values for the rows and the columns so the formula should be sufficient.

Arjen


Bernie Deitrick wrote:
> Arjen,
>
> You can use a macro - select a single cell in your table, then run the macro below.
>
> OR ----
>
> If you have a set number of Letter and Number values, then you could set up a table made up of
> formulas.
>
> With your example database in cells A1:C6 on a sheet named DataBase, and your row and column headers
> in row 1 and column A of a sheet named CrossTab, in cell B2, array enter (enter using
> Ctrl-Shift-Enter) this formula
>
> =IF(SUM((DataBase!$A$1:$A$6='CrossTab'!$A2)*(DataBase!$B$1:$B$6='CrossTab'!B$1)*ROW(DataBase!$B$1:$B$6))=0,"",INDEX(DataBase!$C$1:$C$6,SUM((DataBase!$A$1:$A$6='CrossTab'!$A2)*(DataBase!$B$1:$B$6='CrossTab'!B$1)*ROW(DataBase!$B$1:$B$6))))
>
> And then copy to B24 (which is what your example would produce)....
>
> HTH,
> Bernie
> MS Excel MVP
>
> Sub DBtoCrossTab2()
> Dim myCell As Range
> Dim myTable As Range
> Dim mySht As Worksheet
> Dim myRow As Long
> Dim myCol As Integer
>
> Set myTable = ActiveCell.CurrentRegion
>
> If myTable.Columns.Count <> 3 Then
> MsgBox "This macro works on a 3 column database only"
> Exit Sub
> End If
>
> On Error Resume Next
> Application.DisplayAlerts = False
> Worksheets("Cross Tab").Delete
> Application.DisplayAlerts = True
>
> Set mySht = Worksheets.Add
> mySht.Name = "Cross Tab"
>
> 'myTable.Rows(1).EntireRow.Copy mySht.Rows(1)
>
> Set myTable = myTable.Offset(1, 0).Resize _
> (myTable.Rows.Count - 1, myTable.Columns.Count)
>
> For Each myCell In myTable.Columns(1).Cells
> If IsError(Application.Match(myCell.Value, _
> mySht.Range("A:A"), False)) Then
> mySht.Range("A65536").End(xlUp)(2).Value = myCell.Value
> End If
> If IsError(Application.Match(myCell(1, 2).Value, _
> mySht.Range("1:1"), False)) Then
> mySht.Range("IV1").End(xlToLeft)(1, 2).Value = myCell(1, 2).Value
> End If
>
> myRow = Application.Match(myCell.Value, _
> mySht.Range("A:A"), False)
> myCol = Application.Match(myCell(1, 2).Value, _
> mySht.Range("1:1"), False)
>
> mySht.Cells(myRow, myCol).Value = myCell(1, 3).Value
>
> Next myCell
>
> End Sub
>
>
> "Arjen de Winter" <(E-Mail Removed)> wrote in message
> news:4513fa6b$0$4512$(E-Mail Removed)...
>> Hi All,
>>
>> I'm linking a worksheet to a table on a website on Internet. The data on the table is in the
>> following format:
>>
>> LETTER NUMBER COLOR
>> Alpha One Green
>> Alpha Two Purple
>> Bravo Two Orange
>> Delta Seven Green
>> Delta One Nine
>> Etc.
>>
>>
>> The format I need is the following:
>>
>> NUMBER One Two Three Four Five Six Seven
>> LETTER
>> Alpha Green Purple
>> Bravo Orange
>> Charlie
>> Delta Green
>> Echo Nine
>> Etc.
>>
>>
>> So:
>> The first column in the old table should become row headers (records)
>> The second column should become column headers (fields)
>> The third column should become the data
>>
>>
>> I thought I'd be able to do that with Pivot tables, but that just allows you to summarize, count,
>> etc.
>>
>> I know that the information in the table is unique. E.g. there is no instance where data in a
>> record's field would be filled twice.
>>
>> It's easy enough to import the table into Access, analyze it, and then move it to Excel. However,
>> I want to have a permanent link with the data so that I can instantaneously refresh the
>> information (and the results of the analysis of that information).
>>
>> Thanks,
>>
>>
>> Arjen

>
>

 
Reply With Quote
 
Bernie Deitrick
Guest
Posts: n/a
 
      22nd Sep 2006
Good - glad you like it. Personally, I like the macro better, since there is no maintenance
involved....

HTH,
Bernie
MS Excel MVP


"Arjen de Winter" <(E-Mail Removed)> wrote in message
news:451420ca$0$4512$(E-Mail Removed)...
> Hi Bernie,
>
> This is fantastic. Thank you so much! I do indeed have a set number of values for the rows and the
> columns so the formula should be sufficient.
>
> Arjen
>
>
> Bernie Deitrick wrote:
>> Arjen,
>>
>> You can use a macro - select a single cell in your table, then run the macro below.
>>
>> OR ----
>>
>> If you have a set number of Letter and Number values, then you could set up a table made up of
>> formulas.
>>
>> With your example database in cells A1:C6 on a sheet named DataBase, and your row and column
>> headers in row 1 and column A of a sheet named CrossTab, in cell B2, array enter (enter using
>> Ctrl-Shift-Enter) this formula
>>
>> =IF(SUM((DataBase!$A$1:$A$6='CrossTab'!$A2)*(DataBase!$B$1:$B$6='CrossTab'!B$1)*ROW(DataBase!$B$1:$B$6))=0,"",INDEX(DataBase!$C$1:$C$6,SUM((DataBase!$A$1:$A$6='CrossTab'!$A2)*(DataBase!$B$1:$B$6='CrossTab'!B$1)*ROW(DataBase!$B$1:$B$6))))
>>
>> And then copy to B24 (which is what your example would produce)....
>>
>> HTH,
>> Bernie
>> MS Excel MVP
>>
>> Sub DBtoCrossTab2()
>> Dim myCell As Range
>> Dim myTable As Range
>> Dim mySht As Worksheet
>> Dim myRow As Long
>> Dim myCol As Integer
>>
>> Set myTable = ActiveCell.CurrentRegion
>>
>> If myTable.Columns.Count <> 3 Then
>> MsgBox "This macro works on a 3 column database only"
>> Exit Sub
>> End If
>>
>> On Error Resume Next
>> Application.DisplayAlerts = False
>> Worksheets("Cross Tab").Delete
>> Application.DisplayAlerts = True
>>
>> Set mySht = Worksheets.Add
>> mySht.Name = "Cross Tab"
>>
>> 'myTable.Rows(1).EntireRow.Copy mySht.Rows(1)
>>
>> Set myTable = myTable.Offset(1, 0).Resize _
>> (myTable.Rows.Count - 1, myTable.Columns.Count)
>>
>> For Each myCell In myTable.Columns(1).Cells
>> If IsError(Application.Match(myCell.Value, _
>> mySht.Range("A:A"), False)) Then
>> mySht.Range("A65536").End(xlUp)(2).Value = myCell.Value
>> End If
>> If IsError(Application.Match(myCell(1, 2).Value, _
>> mySht.Range("1:1"), False)) Then
>> mySht.Range("IV1").End(xlToLeft)(1, 2).Value = myCell(1, 2).Value
>> End If
>>
>> myRow = Application.Match(myCell.Value, _
>> mySht.Range("A:A"), False)
>> myCol = Application.Match(myCell(1, 2).Value, _
>> mySht.Range("1:1"), False)
>>
>> mySht.Cells(myRow, myCol).Value = myCell(1, 3).Value
>>
>> Next myCell
>>
>> End Sub
>>
>>
>> "Arjen de Winter" <(E-Mail Removed)> wrote in message
>> news:4513fa6b$0$4512$(E-Mail Removed)...
>>> Hi All,
>>>
>>> I'm linking a worksheet to a table on a website on Internet. The data on the table is in the
>>> following format:
>>>
>>> LETTER NUMBER COLOR
>>> Alpha One Green
>>> Alpha Two Purple
>>> Bravo Two Orange
>>> Delta Seven Green
>>> Delta One Nine
>>> Etc.
>>>
>>>
>>> The format I need is the following:
>>>
>>> NUMBER One Two Three Four Five Six Seven
>>> LETTER
>>> Alpha Green Purple
>>> Bravo Orange
>>> Charlie
>>> Delta Green
>>> Echo Nine
>>> Etc.
>>>
>>>
>>> So:
>>> The first column in the old table should become row headers (records)
>>> The second column should become column headers (fields)
>>> The third column should become the data
>>>
>>>
>>> I thought I'd be able to do that with Pivot tables, but that just allows you to summarize,
>>> count, etc.
>>>
>>> I know that the information in the table is unique. E.g. there is no instance where data in a
>>> record's field would be filled twice.
>>>
>>> It's easy enough to import the table into Access, analyze it, and then move it to Excel.
>>> However, I want to have a permanent link with the data so that I can instantaneously refresh the
>>> information (and the results of the analysis of that information).
>>>
>>> Thanks,
>>>
>>>
>>> Arjen

>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Flat File Database, Multiple Excel files into one Access Table =?Utf-8?B?bGVhcm5pbmdhY2Nlc3M=?= Microsoft Access External Data 6 8th Jul 2007 06:45 PM
Convert Excel Table to Access flat file paras.shah@ericsson.com Microsoft Access Getting Started 5 2nd May 2007 09:28 PM
How to convert a Pivot Table into a Flat File format? lucas.freed@gmail.com Microsoft Excel Misc 1 22nd Feb 2006 05:17 PM
Re: Convert function or expression stored in a table Wayne Morgan Microsoft Access 0 2nd Sep 2004 06:20 PM
Re: Convert function or expression stored in a table '69 Camaro Microsoft Access 0 2nd Sep 2004 04:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:40 AM.