Anyone can suggest a faster way to do this?

edlim85

Board Regular
Joined
May 4, 2009
Messages
178
I have a long list of raw data that i have to prepare into a specific format for a very old machine to read.

I will try my best to explain clearly here. below is one of the sample table, i have about 600 of such tables. i will need to arrange the raw data(image1) into another format below (image2). The tedious part here is some tags(yellow column) have different corresponding coefficient be it coefficient 1, 2, or 3.


image1:
5937560304_e2ea2894bd_z.jpg


if the coefficient is the same i will not need to repeat.

image2:

5937002319_b2331a0f9f.jpg



can anyone help?
 
edlim85,


Sample raw data in worksheet Sheet1 (only showing 39 out of the 181 rows):


Excel Workbook
ABCDEFGHIJ
1TablesFromToTagCoefficient 1coefficient 2coefficient 3Coefficient 4Coefficient 5Coefficient 6
2TU5642008020120080301HRSE11.05NANANANANA
32008020120080301HRSE21.00NANANANANA
4TU5722008020120080301A0.00000.00000.00001.05001.05001.0500
52008020120080301B0.00000.00000.00001.13401.13401.1340
62008020120080301C0.00000.00000.00001.30981.30981.3098
72008020120080301D0.00000.00000.00001.21551.10251.2155
82008020120080301E0.00000.00000.00001.33651.06731.3365
92008020120080301F0.00000.00000.00001.20521.03001.1585
102008020120080301G0.00000.00000.00001.00001.00001.0000
112008020120080301H0.00000.00000.00001.61571.61571.6157
122008020120080301I0.00000.00000.00001.13401.13401.1340
132008020120080301J0.00000.00000.00001.23591.15561.2359
142008020120080301K0.00000.00000.00001.32561.32561.3256
15TU57520080201200803010 - 0.80.00000.00000.00001.17831.01651.0165
1620080201200803010.81 - 10.00000.00000.00001.36471.13221.1655
1720080201200803011.01 - 1.20.00000.00000.00001.60421.34401.3709
1820080201200803011.21 - 1.50.00000.00000.00001.55681.37001.3974
1920080201200803011.51 - 20.00000.00000.00001.57541.44201.4420
2020080201200803012.01 - 2.50.00000.00000.00001.83431.59861.5986
2120080201200803012.51 - 30.00000.00000.00002.09181.82311.8231
2220080201200803013.01 - 50.00000.00000.00002.10882.07002.0700
2320080201200803015.01 - 7.50.00000.00000.00002.37602.37602.3760
2420080201200803017.51 - 100.00000.00000.00002.62202.62202.6220
25200802012008030110.01 - 150.00000.00000.00003.20793.20793.2079
26200802012008030115.01 - 200.00000.00000.00004.20004.20004.2000
27200802012008030120.01 - 300.00000.00000.00004.90004.90004.9000
28200802012008030130.01 - 400.00000.00000.00005.70005.70005.7000
29200802012008030140.01 - 500.00000.00000.00006.50006.50006.5000
30200802012008030150.01 - 600.00000.00000.00007.06007.06007.0600
31200802012008030160.01 - 700.00000.00000.00007.24007.24007.2400
32200802012008030170.01 - 800.00000.00000.00007.42007.42007.4200
33200802012008030180.01 - 900.00000.00000.00007.60007.60007.6000
34200802012008030190.01 - 1000.00000.00000.00007.79007.79007.7900
352008020120080301100.01 - 1100.00000.00000.00007.99007.99007.9900
362008020120080301110.01 - 1200.00000.00000.00008.19008.19008.1900
372008020120080301120.01 - 1300.00000.00000.00008.39008.39008.3900
382008020120080301130.01 - 1400.00000.00000.00008.60008.60008.6000
392008020120080301140.01 - 1500.00000.00000.00008.82008.82008.8200
Sheet1





After the macro in a new worksheet Results (not all columns are shown for brevity):


Excel Workbook
ABCDEFGHIJKLMNOP
1FromToTagCoefficientTagCoefficientTagCoefficientTagCoefficientTagCoefficientTagCoefficientTagCoefficient
22008020120080301HRSE11.05HRSE21
32008020120080301A1.05B1.134C1.3098D1.2155D1.1025E1.3365E1.0673
420080201200803010 - 0.81.17830 - 0.81.01650.81 - 11.36470.81 - 11.13220.81 - 11.16551.01 - 1.21.60421.01 - 1.21.344
52008020120080301V1622.93V1901.7V1125.48V1110.86V1476.33V195.66V24363.7
62008020120080301351.0551351.06351.1361.1079361.06361.1371.1633
72008030220080401HRSE11.05HRSE21
82008030220080401A1.05B1.134C1.3098D1.2155D1.1025E1.3365E1.0673
920080302200804010 - 0.81.17830 - 0.81.01650.81 - 11.36470.81 - 11.13220.81 - 11.16551.01 - 1.21.60421.01 - 1.21.344
102008030220080401V1622.93V1901.7V1125.48V1110.86V1476.33V195.66V24363.7
112008030220080401351.0551351.06351.1361.1079361.06361.1371.1633
12
Results





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ReorgData()
' hiker95, 07/16/2011
' http://www.mrexcel.com/forum/showthread.php?t=564341
Dim w1 As Worksheet, wR As Worksheet
Dim LR As Long, LC As Long, a As Long, aa As Long, LR2 As Long, NC As Long
Dim Area As Range, SR As Long, ER As Long, NR As Long, CName As String
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
w1.UsedRange.Copy wR.Range("A1")
LR = wR.Cells(Rows.Count, 2).End(xlUp).Row
For a = LR To 2 Step -1
  If wR.Cells(a, 1) <> "" Then wR.Rows(a).Insert
Next a
LC = wR.Cells(1, Columns.Count).End(xlToLeft).Column
wR.Range(wR.Cells(1, LC + 5), wR.Cells(1, LC + 6)) = [{"From","To"}]
NR = 1
For Each Area In wR.Range("B2", wR.Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
  With Area
    SR = .Row
    ER = SR + .Rows.Count - 1
    NR = NR + 1
    For a = SR To ER Step 1
      wR.Cells(NR, LC + 5).Resize(, 2).Value = wR.Range("B" & a & ":C" & a).Value
      wR.Columns(LC + 2).Resize(, 2).Clear
      wR.Range(wR.Cells(1, LC + 2), wR.Cells(LC - 5 + 1, LC + 2)).Value = Application.Transpose(wR.Range(wR.Cells(a, 5), wR.Cells(a, LC)).Value)
      LR2 = wR.Cells(Rows.Count, LC + 2).End(xlUp).Row
      With wR.Range(wR.Cells(1, LC + 3), wR.Cells(LR2, LC + 3))
        .FormulaR1C1 = "=COUNTIF(R1C" & LC + 2 & ":RC[-1],RC[-1])"
        .Value = .Value
      End With
      For aa = 1 To LR2 Step 1
        If wR.Cells(aa, LC + 3) = 1 And wR.Cells(aa, LC + 2) <> "NA" And wR.Cells(aa, LC + 2) <> 0 Then
          NC = wR.Cells(NR, Columns.Count).End(xlToLeft).Column + 1
          wR.Cells(NR, NC).Value = wR.Range("D" & a).Value
          wR.Cells(NR, NC + 1).Value = wR.Cells(aa, LC + 2).Value
        End If
      Next aa
    Next a
  End With
Next Area
CName = Replace(Cells(1, LC + 4).Address(0, 0), 1, "")
wR.Columns("A:" & CName).Delete
LC = wR.Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
For a = 3 To LC Step 2
  wR.Cells(1, a).Resize(, 2) = [{"Tag","Coefficient"}]
Next a
wR.UsedRange.Columns.AutoFit
wR.Activate
Application.ScreenUpdating = True
End Sub


Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Then run the ReorgData macro.
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
hi Hiker95,

Thanks for your amazing code. I'm trying my best to digest every line of it. I am very new to vba and im trying understand. :)
 
Upvote 0
edlim85,

You are very welcome.

Glad I could help.

Thanks for the feedback.

Come back anytime.


I am very new to vba and im trying understand.

Training / Books / Sites

MrExcel's Products: Books, CDs, Podcasts Discuss topics related to Holy Macro! Products: Learn Excel from MrExcel, VBA and Macros for Microsoft Excel,Holy Macro! It's 2500 VBA Examples CD, Guerilla Data Analysis Using Microsoft Excel and Excel Knowledge Base CD and the MrExcel Podcasts.
http://www.mrexcel.com/forum/forumdisplay.php?f=19

How to Learn to Write Macros
http://articles.excelyogi.com/playin...ba/2008/10/27/

How to use the macro recorder
http://articles.excelyogi.com/

Click here and scroll down to Getting Started with VBA.
http://www.datapigtechnologies.com/ExcelMain.htm

If you are serious about learning VBA try
http://www.add-ins.com/vbhelp.htm

Excel Tutorials and Tips - VBA - macros - training
http://www.mrexcel.com/articles.shtml

See David McRitchie's site if you just started with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm

What is a Visual Basic Module?
http://www.emagenit.com/VBA Folder/what_is_a_vba_module.htm

Debra Dalgleish has some notes how to implement macros here:
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

Creating custom functions
http://office.microsoft.com/en-us/excel/HA011117011033.aspx

Writing Your First VBA Function in Excel
http://www.exceltip.com/st/Writing_Your_First_VBA_Function_in_Excel/631.html

Where to paste code in VBE VBA
Introducing the Excel VBA Editor
http://www.ask.com/web?qsrc=2417&o=101881&l=dis&q=Where+to+paste+code+in+the+Excel+VBA+Editor

VBA for Excel (Macros)
http://www.excel-vba.com/excel-vba-contents.htm

VBA Lesson 11: VBA Code General Tips and General Vocabulary
http://www.excel-vba.com/vba-code-2-1-tips.htm

Excel VBA -- Adding Code to a Workbook
http://www.contextures.com/xlvba01.html

http://www.excel-vba.com/
http://www.mvps.org/dmcritchie/excel/getstarted.htm
http://www.exceltip.com/excel_links.html

(livelessons video)
Excel VBA and Macros with MrExcel
ISBN: 0-7897-3938-0
http://www.amazon.com/Excel-Macros-M...7936479&sr=1-1

Excel Tutorials / Video Tutorials - Functions
http://www.contextures.com/xlFunctions02.html

http://www.xl-central.com/index.html

http://www.datapigtechnologies.com/ExcelMain.htm

Cascading queries

http://www.tushar-mehta.com/excel/ne...ing_dropdowns/

Excel VLOOKUP Function and VLOOKUP Example
http://www.contextures.com/xlFunctions02.html

INDEX MATCH - Excel Index Function and Excel Match Function
http://www.contextures.com/xlFunctions03.html

http://www.contextures.com/xlDataVal02.html
http://www.contextures.com/xlDataVal05.html
http://www.contextures.com/xlDataVal08.html#Larger

Excel Data Validation - Add New Items
http://www.contextures.com/excel-data-validation-add.html

Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
This page describes how to write code that modifies or reads other VBA code.
http://www.cpearson.com/Excel/vbe.aspx

Locating files containing VBA
Searching Files in Subfolders for VBA code string:
http://www.dailydoseofexcel.com/arch...a-code-string/

http://www.pcreview.co.uk/forums/thread-978054.php

Excel 2003 Power Programming with VBA (Excel Power Programming With Vba)
by John Walkenbach

VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel 2007 Book: you can try this...there is a try before you buy ebook available at this link…
http://www.mrexcel.com/learnexcel2.shtml

Professional Excel Development
by Stephen/ Bovey, Rob/ Green, John Bullen (Paperback - Feb 11, 2005)

Excel 2002 VBA: Programmers Reference
by Rob Bovey, Stephen Bullen, John Green, and Robert Rosenberg (Paperback - Sep 26, 2001)

VB & VBA in a Nutshell: The Language
(http://www.amazon.co.uk/VB-VBA-Nutsh...4671189&sr=1-2)

Writing Excel Macros with VBA
(http://www.amazon.co.uk/Writing-Exce...4671189&sr=1-3)

User Form Creation
http://www.contextures.com/xlUserForm01.html

DonkeyOte: My Recommended Reading
Volatility
http://www.decisionmodels.com/calcsecretsi.htm

Sumproduct
http://www.xldynamic.com/source/xld.SUMPRODUCT.html
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

Arrays
http://www.xtremevbtalk.com/showthread.php?t=296012

Pivot Intro
http://peltiertech.com/Excel/Pivots/pivotstart.htm

Email from XL - VBA
http://www.rondebruin.nl/sendmail.htm

Outlook VBA
http://www.outlookcode.com/article.aspx?ID=40

Function Dictionary
http://www.xlfdic.com/

Function Translations
http://www.piuha.fi/excel-function-name-translation/

Dynamic Named Ranges
http://www.contextures.com/xlNames01.html

How to create Excel Dashboards
http://www.contextures.com/excel-dashboards.html
http://chandoo.org/wp/excel-dashboards/
http://chandoo.org/wp/management-dashboards-excel/
http://www.exceldashboardwidgets.com/

Excel Dashboard / Scorecard Ebook
http://www.qimacros.com/excel-dashboard-scorecard.html

Mike Alexander from Data Pig Technologies
Excel 2007 Dashboards & Reports For Dummies
 
Upvote 0
Hi all,

This might be demanding, but can anyone explain to me what each line of the codes is doing by commenting?

I have been reading up some basics of vba in the given list of websites above. Also on basics of declaring variables.

Option Explicit<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Sub ReorgData()<o:p></o:p>
' hiker95, 07/16/2011<o:p></o:p>
' http://www.mrexcel.com/forum/showthread.php?t=564341<o:p></o:p>
Dim w1 As Worksheet, wR As Worksheet<o:p></o:p>
Dim LR As Long, LC As Long, a As Long, aa As Long, LR2 As Long, NC As Long<o:p></o:p>
Dim Area As Range, SR As Long, ER As Long, NR As Long, CName As String<o:p></o:p>
Application.ScreenUpdating = False<o:p></o:p>
Set w1 = Worksheets("Sheet1")<o:p></o:p>
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"<o:p></o:p>
Set wR = Worksheets("Results")<o:p></o:p>
wR.UsedRange.Clear<o:p></o:p>
w1.UsedRange.Copy wR.Range("A1")<o:p></o:p>
LR = wR.Cells(Rows.Count, 2).End(xlUp).Row<o:p></o:p>
For a = LR To 2 Step -1<o:p></o:p>
If wR.Cells(a, 1) <> "" Then wR.Rows(a).Insert<o:p></o:p>
Next a<o:p></o:p>
LC = wR.Cells(1, Columns.Count).End(xlToLeft).Column<o:p></o:p>
wR.Range(wR.Cells(1, LC + 5), wR.Cells(1, LC + 6)) = [{"From","To"}]<o:p></o:p>
NR = 1<o:p></o:p>
For Each Area In wR.Range("B2", wR.Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas<o:p></o:p>
With Area<o:p></o:p>
SR = .Row<o:p></o:p>
ER = SR + .Rows.Count - 1<o:p></o:p>
NR = NR + 1<o:p></o:p>
For a = SR To ER Step 1<o:p></o:p>
wR.Cells(NR, LC + 5).Resize(, 2).Value = wR.Range("B" & a & ":C" & a).Value<o:p></o:p>
wR.Columns(LC + 2).Resize(, 2).Clear<o:p></o:p>
wR.Range(wR.Cells(1, LC + 2), wR.Cells(LC - 5 + 1, LC + 2)).Value = Application.Transpose(wR.Range(wR.Cells(a, 5), wR.Cells(a, LC)).Value)<o:p></o:p>
LR2 = wR.Cells(Rows.Count, LC + 2).End(xlUp).Row<o:p></o:p>
With wR.Range(wR.Cells(1, LC + 3), wR.Cells(LR2, LC + 3))<o:p></o:p>
.FormulaR1C1 = "=COUNTIF(R1C" & LC + 2 & ":RC[-1],RC[-1])"<o:p></o:p>
.Value = .Value<o:p></o:p>
End With<o:p></o:p>
For aa = 1 To LR2 Step 1<o:p></o:p>
If wR.Cells(aa, LC + 3) = 1 And wR.Cells(aa, LC + 2) <> "NA" And wR.Cells(aa, LC + 2) <> 0 Then<o:p></o:p>
NC = wR.Cells(NR, Columns.Count).End(xlToLeft).Column + 1<o:p></o:p>
wR.Cells(NR, NC).Value = wR.Range("D" & a).Value<o:p></o:p>
wR.Cells(NR, NC + 1).Value = wR.Cells(aa, LC + 2).Value<o:p></o:p>
End If<o:p></o:p>
Next aa<o:p></o:p>
Next a<o:p></o:p>
End With<o:p></o:p>
Next Area<o:p></o:p>
CName = Replace(Cells(1, LC + 4).Address(0, 0), 1, "")<o:p></o:p>
wR.Columns("A:" & CName).Delete<o:p></o:p>
LC = wR.Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column<o:p></o:p>
For a = 3 To LC Step 2<o:p></o:p>
wR.Cells(1, a).Resize(, 2) = [{"Tag","Coefficient"}]<o:p></o:p>
Next a<o:p></o:p>
wR.UsedRange.Columns.AutoFit<o:p></o:p>
wR.Activate<o:p></o:p>
Application.ScreenUpdating = True<o:p></o:p>
End Sub<o:p></o:p>





</PRE>
thanks a million in advance.


regards
Edmund
 
Upvote 0
I went on the try decipher and F8 thru the lines. im stuck at red and below onwards.

Pls explain to me:
SR = .Row
ER = SR + .Rows.Count - 1
NR = NR + 1
For a = SR To ER Step 1

For a = SR To ER Step 1

regards
edmund

Dim w1 As Worksheet, wR As Worksheet
Dim LR As Long, LC As Long, a As Long, aa As Long, LR2 As Long, NC As Long
Dim Area As Range, SR As Long, ER As Long, NR As Long, CName As String
Application.ScreenUpdating = False
Set w1 = Worksheets("Ratings-Table")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
w1.UsedRange.Copy wR.Range("A1") ‘copy and paste used range data from w1 to wR
LR = wR.Cells(Rows.Count, 2).End(xlUp).Row row number of the bottommost non-empty cell in column A.
For a = LR To 2 Step -1 ‘Sets a to LR, subtract 1 to a until a=2, loops 2 times.
If wR.Cells(a, 1) <> "" Then wR.Rows(a).Insert ‘insert
Next a ‘if cell is empty then next a..if not insert row on top.
LC = wR.Cells(1, Columns.Count).End(xlToLeft).Column ‘column number of the right most, non empty cell in row 1
wR.Range(wR.Cells(1, LC + 5), wR.Cells(1, LC + 6)) = [{"From","To"}] ‘Row1 column O and P
NR = 1
For Each Area In wR.Range("B2", wR.Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas ‘selects non empty cells in column B.
With Area
SR = .Row 'SR equals to row
ER = SR + .Rows.Count – 1 ‘ER = row and row count subtract 1
NR = NR + 1
For a = SR To ER Step 1 ‘Sets a to SR, add 1 to a until a= row and row count subtract 1,
wR.Cells(NR, LC + 5).Resize(, 2).Value = wR.Range("B" & a & ":C" & a).Value ‘paste date<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
wR.Columns(LC + 2).Resize(, 2).Clear
‘result worksheet select range = cell[row1, right most, non empty cell in row 1+2] : cell[right most, non empty cell in row 1 – 5 + 1, right most, non empty cell in row 1 +2 = transpose range<o:p></o:p>
wR.Range(wR.Cells(1, LC + 2), wR.Cells(LC - 5 + 1, LC + 2)).Value = Application.Transpose(wR.Range(wR.Cells(a, 5), wR.Cells(a, LC)).Value)
LR2 = wR.Cells(Rows.Count, LC + 2).End(xlUp).Row ‘
With wR.Range(wR.Cells(1, LC + 3), wR.Cells(LR2, LC + 3))
.FormulaR1C1 = "=COUNTIF(R1C" & LC + 2 & ":RC[-1],RC[-1])"
.Value = .Value
End With
For aa = 1 To LR2 Step 1
If wR.Cells(aa, LC + 3) = 1 And wR.Cells(aa, LC + 2) <> "NA" And wR.Cells(aa, LC + 2) <> 0 Then
NC = wR.Cells(NR, Columns.Count).End(xlToLeft).Column + 1
wR.Cells(NR, NC).Value = wR.Range("D" & a).Value
wR.Cells(NR, NC + 1).Value = wR.Cells(aa, LC + 2).Value
End If
Next aa
Next a
End With
Next Area
CName = Replace(Cells(1, LC + 4).Address(0, 0), 1, "")
wR.Columns("A:" & CName).Delete
LC = wR.Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
For a = 3 To LC Step 2
wR.Cells(1, a).Resize(, 2) = [{"Tag","Coefficient"}]
Next a
wR.UsedRange.Columns.AutoFit
wR.Activate
Application.ScreenUpdating = True
End Sub
 
Upvote 0
edlim85,

Per your private request.


Instructions on what the code is doing, see below in bold for the first Area.


Rich (BB code):
Option Explicit
Sub ReorgData()
' hiker95, 07/16/2011
' http://www.mrexcel.com/forum/showthread.php?t=564341
Dim w1 As Worksheet, wR As Worksheet
Dim LR As Long, LC As Long, a As Long, aa As Long, LR2 As Long, NC As Long
Dim Area As Range, SR As Long, ER As Long, NR As Long, CName As String
Application.ScreenUpdating = False

'Set the variable w1 to worksheet Sheet1
Set w1 = Worksheets("Sheet1")

'If worksheet Results does NOT exist, then add the worksheet
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"

'Set the variable wR to worksheet Results
Set wR = Worksheets("Results")

'If worksheet wR does exist, then clear the worksheet
wR.UsedRange.Clear

'Copy the used range of w1 to wR
w1.UsedRange.Copy wR.Range("A1")

'Find the last used row in wR in column 2 = column B
LR = wR.Cells(Rows.Count, 2).End(xlUp).Row

'Loop thru wR, column A, from the last row to row 2
'  to split/separate the data into groups, Area's
For a = LR To 2 Step -1

  'If the cell is NOT blank then insert a row
  If wR.Cells(a, 1) <> "" Then wR.Rows(a).Insert
Next a

'Find the last column in wR in row 1
'  which is equal to column J = 10
LC = wR.Cells(1, Columns.Count).End(xlToLeft).Column

'In this case/example in cell O1 put "From", in cell P1 put "To"
wR.Range(wR.Cells(1, LC + 5), wR.Cells(1, LC + 6)) = [{"From","To"}]

'Set the next row in in column O and P
NR = 1

'Loop thur each Area in column B, from B2 to the last row
For Each Area In wR.Range("B2", wR.Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
  
  'Within each Area
  With Area
    
    'StartRrow is the first row in the Area
    SR = .Row
    
    'EndRow is equal to SR + the count of rows in the Area - 1
    ER = SR + .Rows.Count - 1
    
    'The next available blank row is NR + NR + 1
    NR = NR + 1
    
    'Loop thru the rows in each Area from the SR to ER of the Area
    ' FOR THE FIRST CASE (Area), ROWS 3 AND 4
    For a = SR To ER Step 1
    
      'Cells O NR, P NR, is equal to column B row a (ROW 3), column C row a (ROW 3)
      wR.Cells(NR, LC + 5).Resize(, 2).Value = wR.Range("B" & a & ":C" & a).Value
      
      'in a work column, LC + 2 = column L
      '  clear the column
      wR.Columns(LC + 2).Resize(, 2).Clear
      
      'Transpose the values in E3:J3 to L1
      wR.Range(wR.Cells(1, LC + 2), wR.Cells(LC - 5 + 1, LC + 2)).Value = Application.Transpose(wR.Range(wR.Cells(a, 5), wR.Cells(a, LC)).Value)
      
      'LR2 = last row in column L = ROW 6
      LR2 = wR.Cells(Rows.Count, LC + 2).End(xlUp).Row
      
      'In range "M1:M6
      With wR.Range(wR.Cells(1, LC + 3), wR.Cells(LR2, LC + 3))
        
        'put the formula =COUNTIF($L$1:L1,L1)
        .FormulaR1C1 = "=COUNTIF(R1C" & LC + 2 & ":RC[-1],RC[-1])"
        
        'change the formula to values
        .Value = .Value
      End With
      
      'Loop thru M1 to M6
      For aa = 1 To LR2 Step 1
      
        'If M1 = 1, and L1 <> "NA", and L1 <> 0
        If wR.Cells(aa, LC + 3) = 1 And wR.Cells(aa, LC + 2) <> "NA" And wR.Cells(aa, LC + 2) <> 0 Then
          
          'Find the NC, next available column in the NR = ROW 2
          NC = wR.Cells(NR, Columns.Count).End(xlToLeft).Column + 1
          
          'cell Q2 = cell D3 = "HRSE1"
          wR.Cells(NR, NC).Value = wR.Range("D" & a).Value
          
          'cell R2 = cell L1 = 1.05
          wR.Cells(NR, NC + 1).Value = wR.Cells(aa, LC + 2).Value
        End If
      Next aa
    Next a
  End With
Next Area

'After the new table is created, delete columns A thru N
'CName = LC + 4 = "N"
CName = Replace(Cells(1, LC + 4).Address(0, 0), 1, "")
wR.Columns("A:" & CName).Delete

'Find the last used column in the worksheet
LC = wR.Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column

'Put the titles in row 1, beginning in column 3 = "C"
For a = 3 To LC Step 2
  wR.Cells(1, a).Resize(, 2) = [{"Tag","Coefficient"}]
Next a

'Set the column width for all the columns in the worksheet used range to AutoFit
wR.UsedRange.Columns.AutoFit

'Activate the wR worksheet
wR.Activate
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi hiker95,

Thanks for your prompt reply. I definitely didnt expect your reply to so soon. Time for a deeper digestion of your codes.


Thanks again.

Regards
Edmund
 
Upvote 0
Hi hiker95,

I went thru the codes. Going forward if i have to compile my data vertically according to coefficient 1, coefficient 2 and so on, can i add another For Each column statement wrapping around the For each row statement in the your original codes. I tried doing that but it will not go the the next col, must be my codings are wrong.:eeek: what is the right way of doing it?


using the same raw data.
<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 11pt; FONT-FAMILY: Calibri,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 63px"><COL style="WIDTH: 84px"><COL style="WIDTH: 84px"><COL style="WIDTH: 97px"><COL style="WIDTH: 97px"><COL style="WIDTH: 97px"><COL style="WIDTH: 97px"><COL style="WIDTH: 97px"><COL style="WIDTH: 97px"><COL style="WIDTH: 97px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD> </TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD><TD>H</TD><TD>I</TD><TD>J</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; TEXT-ALIGN: center">Tables</TD><TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; TEXT-ALIGN: center">From</TD><TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif">To</TD><TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">Tag</TD><TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">Coefficient 1</TD><TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">coefficient 2</TD><TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">coefficient 3</TD><TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">Coefficient 4</TD><TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">Coefficient 5</TD><TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">Coefficient 6</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD style="FONT-SIZE: 10pt; TEXT-ALIGN: center">TU564</TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">HRSE1</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.05</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">NA</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">NA</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">NA</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">NA</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">NA</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">HRSE2</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.00</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">NA</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">NA</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">NA</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">NA</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">NA</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD style="FONT-SIZE: 10pt; TEXT-ALIGN: center">TU572</TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">A</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.0500</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.0500</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.0500</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">B</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.1340</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.1340</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.1340</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">6</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">C</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.3098</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.3098</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.3098</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">7</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">D</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.2155</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.1025</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.2155</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">8</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">E</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.3365</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.0673</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.3365</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">9</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">F </TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.2052</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.0300</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.1585</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">10</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">G</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.0000</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">11</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">H</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.6157</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.6157</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.6157</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">12</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">I</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.1340</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.1340</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.1340</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">13</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">J</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.2359</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.1556</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.2359</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">14</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: MS Sans Serif"> </TD><TD style="TEXT-ALIGN: right">20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #ffff00; TEXT-ALIGN: center">K </TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">0.0000</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.3256</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.3256</TD><TD style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #99ccff; TEXT-ALIGN: center">1.3256</TD></TR></TBODY></TABLE>


the result will be

<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 11pt; FONT-FAMILY: Calibri,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 84px"><COL style="WIDTH: 84px"><COL style="WIDTH: 59px"><COL style="WIDTH: 97px"><COL style="WIDTH: 59px"><COL style="WIDTH: 97px"><COL style="WIDTH: 59px"><COL style="WIDTH: 97px"><COL style="WIDTH: 59px"><COL style="WIDTH: 97px"><COL style="WIDTH: 59px"><COL style="WIDTH: 97px"><COL style="WIDTH: 59px"><COL style="WIDTH: 97px"><COL style="WIDTH: 59px"><COL style="WIDTH: 97px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD> </TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD><TD>H</TD><TD>I</TD><TD>J</TD><TD>K</TD><TD>L</TD><TD>M</TD><TD>N</TD><TD>O</TD><TD>P</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD>Table</TD><TD>Item</TD><TD>From</TD><TD>To</TD><TD>Tag</TD><TD>Coefficient</TD><TD>Tag</TD><TD>Coefficient</TD><TD>Tag</TD><TD>Coefficient</TD><TD>Tag</TD><TD>Coefficient</TD><TD>Tag</TD><TD>Coefficient</TD><TD>Tag</TD><TD>Coefficient</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD style="TEXT-ALIGN: right">TU564</TD><TD style="TEXT-ALIGN: right">Coefficient 1</TD><TD>20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD>HRSE1</TD><TD style="TEXT-ALIGN: right">1.05</TD><TD> HRSE2</TD><TD> 1.00</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD style="TEXT-ALIGN: right">TU572</TD><TD style="TEXT-ALIGN: right">Coefficient 4</TD><TD>20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD>A</TD><TD style="TEXT-ALIGN: right">1.0500</TD><TD>B</TD><TD style="TEXT-ALIGN: right">1.1340</TD><TD>C</TD><TD style="TEXT-ALIGN: right">1.3098</TD><TD>D</TD><TD style="TEXT-ALIGN: right">1.2155</TD><TD>E</TD><TD style="TEXT-ALIGN: right">1.3365</TD><TD>F</TD><TD style="TEXT-ALIGN: right">1.2052</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD style="TEXT-ALIGN: right">TU572</TD><TD style="TEXT-ALIGN: right">Coefficient 5</TD><TD>20080201</TD><TD style="TEXT-ALIGN: right">20080301</TD><TD>A</TD><TD style="TEXT-ALIGN: right">1.0165</TD><TD>B</TD><TD style="TEXT-ALIGN: right">1.3647</TD><TD>C</TD><TD style="TEXT-ALIGN: right">1.1322</TD><TD>D</TD><TD style="TEXT-ALIGN: right">1.1025</TD><TD>E</TD><TD style="TEXT-ALIGN: right">1.0673</TD><TD>F</TD><TD style="TEXT-ALIGN: right">1.0300</TD></TR></TBODY></TABLE>

From the original codes, Col A and B are added on. hence this display data taged vertically. ie first the codes go by each column (col E), then go into the rows of col E, then next column (col F) and its rows...and so on til end of data.

Regards
Edmund
 
Upvote 0
given my understanding, i tried adding some code on top of the "For each row" statement. "compile error. invalid next control variable reference" i guess this tells me that my next statement is wrong.:laugh: argh.

For Each Area1 In wR.Range("E2", wR.Range("E" & Columns.Count).End(xlToLeft)).SpecialCells(xlCellTypeConstants).Areas
With Area1
SC = .Column
ER = SC + .Columns.Count - 1
NC1 = NC1 + 1
For aaa = SC To EC Step 1

For Each Area In Area1.SpecialCells(xlCellTypeConstants).Areas
With Area
SR = .Row
ER = SR + .Rows.Count - 1
NR = NR + 1
For a = SR To ER Step 1
wR.Cells(NR, LC + 5).Resize(, 2).Value = wR.Range("B" & a & ":C" & a).Value
wR.Columns(LC + 2).Resize(, 2).Clear
wR.Range(wR.Cells(1, LC + 2), wR.Cells(ER - 5, LC + 2)).Value = wR.Cells(aa, ER).Value
LR2 = wR.Cells(Rows.Count, LC + 2).End(xlUp).Row
With wR.Range(wR.Cells(1, LC + 3), wR.Cells(LR2, LC + 3))
.FormulaR1C1 = "=COUNTIF(R1C" & LC + 2 & ":RC[-1],RC[-1])"
.Value = .Value
End With

For aa = 1 To LR2 Step 1
If wR.Cells(aa, LC + 3) = 1 And wR.Cells(aa, LC + 2) <> "NA" And wR.Cells(aa, LC + 2) <> 0 Then
NC = wR.Cells(NR, Columns.Count).End(xlToLeft).Column + 1
wR.Cells(NR, NC).Value = wR.Range("D" & a).Value
wR.Cells(NR, NC + 1).Value = wR.Cells(aa, LC + 2).Value
End If
Next aa
Next a
End With
Next Area
Next Area1
 
Upvote 0
edlim85,

I can understand the additional columns A and B in worksheet Results.

What I can not understand is:

In my last posted Results worksheet, my Reply #11 , row 3, contains 2 D values and 2 E values, based on prior guidelines.

Your Results worksheet for row 3, only contains 1 D value and 1 E value.

And, I can not see where you are getting the data for row 4.


Please click on the Post Reply button, and just put the word BUMP in the post. Then, click on the Submit Reply button, and someone else will assist you.
 
Upvote 0

Forum statistics

Threads
1,224,530
Messages
6,179,373
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top