LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Convert an Excel table to a list with VBA

This is not a very sophisticated response, however, it will do the job.
Might be a good guide for a start.

Sub BuildTable()
Dim strWeek As String, strActivity As String, intRow As Integer, intCol
As Integer
Dim strQty As String, strRange As String

'Go to New Sheet and prepare table header
Sheets("Sheet2").Select
'Range("A1").Select 'raises error 1004 "not defined" ???
ActiveCell.Select
ActiveCell.Formula = "Desc"
'Range("B1").Select 'raises error 1004 "not defined" ???
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = "Activity"
'Range("C1").Select 'raises error 1004 "not defined" ???
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = "Qty"
ActiveCell.Offset(1, -2).Select
'Return to original data
Sheets("Sheet1").Select
'Cycle through original data
For intCol = 2 To 5 'For each column
Select Case intCol
Case 2: strRange = "B"
Case 3: strRange = "C"
Case 4: strRange = "D"
Case 5: strRange = "E"
End Select
Range(strRange & "2").Select
'Collect the column title
ActiveCell.Offset(-1, 0).Select
strWeek = ActiveCell.Text
ActiveCell.Offset(1, 0).Select

For intRow = 2 To 4 ' For each Row
Range(strRange & CStr(intRow)).Select
'Collect the row title
ActiveCell.Offset(0, -intCol + 1).Select
strActivity = ActiveCell.Text
ActiveCell.Offset(0, intCol - 1).Select
'if there is a quantity in the cell
If ActiveCell.Text < "" Then
strQty = ActiveCell.Text
Sheets("Sheet2").Select
'Range("A2").Select
While ActiveCell.Text < ""
ActiveCell.Offset(1, 0).Select
Wend
ActiveCell.Formula = strWeek
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = strActivity
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = strQty
ActiveCell.Offset(1, -2).Select
Sheets("Sheet1").Select
End If

Next intRow

Next intCol

End Sub


Good luck from Tasmania

" wrote:

I want to convert a table to a list
I am still struggling with VBA.
I have not been able to find a similar example.
Can anyone help ?

Thank you.

Wayne.

Input table - WorkSheet A
-------------------------
Week1 Week2 Week3 week4
Activity 1 1
Activity 2 2 3
Activity 3 2 5 4

Wanted output list on WorkSheet B

Desc Activity Qty
-----------------------------------
Week 1 Activity 1 1
Week 1 Activity 3 2
Week 2 Activity 2 2
Week 3 Activity 3 5
Week 4 Activity 2 3
Week 4 Activity 3 4


 
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
How do I convert a table into a list in excel? scott Excel Worksheet Functions 8 June 30th 08 03:05 AM
Convert list to table Phelit Excel Discussion (Misc queries) 1 May 28th 08 04:09 PM
How to convert a table to list? ferdi Excel Worksheet Functions 1 March 17th 07 03:14 AM
How to convert existing Excel List into a table in Access? anna New Users to Excel 2 June 18th 06 11:57 PM
convert excel list to pivot table GI Excel Discussion (Misc queries) 0 December 6th 04 06:45 PM


All times are GMT +1. The time now is 11:54 AM.

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"