#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Macro help

How can I set a marco to transfer data from a table format to a database format, for example
This is the table format
Jan-04 Paris Mila
Income 100 3
Rent -40 -

Like to become
Income Jan-04 Paris 10
Income Jan-04 Milan 3
Rent Jan-04 Paris -4
Rent Jan-04 Milan -

Thanks!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro help

Hi Jammy,

Here's some code

Sub MakeDB()
Dim cLastRow As Long
Dim cLastCol As Long
Dim i As Long, j As Long
Dim iTarget As Long
Dim shThis As Worksheet

Set shThis = ActiveSheet
Worksheets.Add
With shThis
cLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
cLastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To cLastRow
For j = 2 To cLastCol
iTarget = iTarget + 1
ActiveSheet.Cells(iTarget, 1).Value = .Cells(i, 1).Value
ActiveSheet.Cells(iTarget, 2).Value = .Cells(1, 1).Value
ActiveSheet.Cells(iTarget, 3).Value = .Cells(1, j).Value
ActiveSheet.Cells(iTarget, 4).Value = .Cells(i, j).Value
Next j
Next i
End With
End Sub

Was the sample workbook man y good?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Janmy" wrote in message
...
How can I set a marco to transfer data from a table format to a database

format, for example:
This is the table format:
Jan-04 Paris Milan
Income 100 30
Rent -40 -5

Like to become:
Income Jan-04 Paris 100
Income Jan-04 Milan 30
Rent Jan-04 Paris -40
Rent Jan-04 Milan -5

Thanks!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Macro help

Hi Bob

Thank you very much for your help. I 'm still working hard on it. It works!

Regards.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Macro help

Thanks Bob
I'm still trying to work out the worksheet. But for the following macro, please help me to exclude subtotal or blank line when making the DB

Regards


----- Bob Phillips wrote: ----

Hi Jammy

Here's some cod

Sub MakeDB(
Dim cLastRow As Lon
Dim cLastCol As Lon
Dim i As Long, j As Lon
Dim iTarget As Lon
Dim shThis As Workshee

Set shThis = ActiveShee
Worksheets.Ad
With shThi
cLastRow = .Cells(Rows.Count, "A").End(xlUp).Ro
cLastCol = .Cells(1, Columns.Count).End(xlToLeft).Colum
For i = 2 To cLastRo
For j = 2 To cLastCo
iTarget = iTarget +
ActiveSheet.Cells(iTarget, 1).Value = .Cells(i, 1).Valu
ActiveSheet.Cells(iTarget, 2).Value = .Cells(1, 1).Valu
ActiveSheet.Cells(iTarget, 3).Value = .Cells(1, j).Valu
ActiveSheet.Cells(iTarget, 4).Value = .Cells(i, j).Valu
Next
Next
End Wit
End Su

Was the sample workbook man y good

--

HT

Bob Phillip
... looking out across Poole Harbour to the Purbeck
(remove nothere from the email address if mailing direct

"Janmy" wrote in messag
..
How can I set a marco to transfer data from a table format to a databas

format, for example
This is the table format
Jan-04 Paris Mila
Income 100 3
Rent -40 -
Like to become

Income Jan-04 Paris 10
Income Jan-04 Milan 3
Rent Jan-04 Paris -4
Rent Jan-04 Milan -
Thanks!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro help

Hi Jammy,

Try this

Sub MakeDB()
Dim cLastRow As Long
Dim cLastCol As Long
Dim i As Long, j As Long
Dim iTarget As Long
Dim shThis As Worksheet

Set shThis = ActiveSheet
Worksheets.Add.Name = "DB"
With shThis
cLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
cLastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To cLastRow
If .Cells(i, "A") < "" And Not .Cells(i, "A") Like "Total" Then
For j = 2 To cLastCol
iTarget = iTarget + 1
ActiveSheet.Cells(iTarget, 1).Value = .Cells(i, 1).Value
ActiveSheet.Cells(iTarget, 2).Value = .Cells(1, 1).Value
ActiveSheet.Cells(iTarget, 3).Value = .Cells(1, j).Value
ActiveSheet.Cells(iTarget, 4).Value = .Cells(i, j).Value
Next j
End If
Next i
End With
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Janmy" wrote in message
...
Thanks Bob,
I'm still trying to work out the worksheet. But for the following macro,

please help me to exclude subtotal or blank line when making the DB.

Regards.



----- Bob Phillips wrote: -----

Hi Jammy,

Here's some code

Sub MakeDB()
Dim cLastRow As Long
Dim cLastCol As Long
Dim i As Long, j As Long
Dim iTarget As Long
Dim shThis As Worksheet

Set shThis = ActiveSheet
Worksheets.Add
With shThis
cLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
cLastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To cLastRow
For j = 2 To cLastCol
iTarget = iTarget + 1
ActiveSheet.Cells(iTarget, 1).Value = .Cells(i,

1).Value
ActiveSheet.Cells(iTarget, 2).Value = .Cells(1,

1).Value
ActiveSheet.Cells(iTarget, 3).Value = .Cells(1,

j).Value
ActiveSheet.Cells(iTarget, 4).Value = .Cells(i,

j).Value
Next j
Next i
End With
End Sub

Was the sample workbook man y good?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Janmy" wrote in message
...
How can I set a marco to transfer data from a table format to a

database
format, for example:
This is the table format:
Jan-04 Paris Milan
Income 100 30
Rent -40 -5
Like to become:

Income Jan-04 Paris 100
Income Jan-04 Milan 30
Rent Jan-04 Paris -40
Rent Jan-04 Milan -5
Thanks!!








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
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 1 February 5th 07 09:31 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 03:17 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"