Solved

Spreadsheet reformatting

Posted on 2014-04-01
11
211 Views
Last Modified: 2014-04-01
Excel 2000. I know, it's old. So am I.

I have been sent a spreadsheet that is just data -- no formulas or references. It looks something like this:
Type1     Data1A     Data1B     Data1C      Data1D ... Data1U
Type2     Data2A     Data2B     Data2C      Data2D ... Data2U 
...
Type321     Data321A     Data321B     Data321C      Data321D ... Data321U
Type322     Data322A     Data322B     Data322C      Data322D ... Data322U 

Open in new window

In other words, 322 rows across 21 columns. What I need is something like this:
Type1
Data1A
Data1B
Data1C
Data1D
...
Data1U
Type2
Data2A
Data2B
Data2C
Data2D
...
Data2U
...
Type321
Data321A
Data321B
Data321C
Data321D
...
Data321U
Type322
Data322A
Data322B
Data322C
Data322D
...
Data322U

Open in new window

I know I could probably track down someone who could very quickly and easily write up something that would churn out such a list, but then I wouldn't learn anything... So can someone point me in the right direction?

Thanks!

ep
0
Comment
Question by:ericpete
  • 6
  • 3
  • 2
11 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 450 total points
ID: 39971150
Hi Eric,

With a formula, in a new sheet, starting in cell A1, and assuming that your data is in sheet1, use the following then copy down as far as your data goes:

=OFFSET(Sheet1!$A$1, INT(ROW()/23),MOD(ROW()-1,22),1,1)

You add one row every 23 rows and add a column in a cycle of 22.


Macro solution is very workable too.

Thomas
0
 
LVL 15

Author Comment

by:ericpete
ID: 39971180
Thomas,

That worked perfectly. I hate to ask (okay, not really -- I'm trying to understand what I'm doing), but can you explain what's going on?

And for giggles and grins, how would I implement a macro that does the same thing?

ep
0
 
LVL 80

Assisted Solution

by:byundt
byundt earned 50 total points
ID: 39971212
Eric,
In case you want a macro, here is one that will work for any number of rows and columns of data. The macro assumes that the data starts in cell A1. It reads the data into an array, then writes the results to a different array. Upon completion, it clears the initial data and replaces it with the single column results array.

Install the macro in a regular module sheet.
Sub Normalizer()
Dim rg As Range
Dim i As Long, j As Long, k As Long, nCols As Long, nRows As Long
Dim v As Variant, vData As Variant
Application.ScreenUpdating = False
Set rg = Range("A1").CurrentRegion
nCols = rg.Columns.Count
nRows = rg.Rows.Count
ReDim v(1 To nRows * nCols, 1 To 1)
vData = rg.Value
For i = 1 To nRows
    For j = 1 To nCols
        k = k + 1
        v(k, 1) = vData(i, j)
    Next
Next
rg.ClearContents
rg.Cells(1, 1).Resize(k, 1).Value = v
End Sub

Open in new window

Brad
DataNormalizerQ28402864.xls
0
 
LVL 39

Assisted Solution

by:nutsch
nutsch earned 450 total points
ID: 39971223
Offset starts from an anchor range and returns another range with a specified offset. In this case, you start at cell a1 and move to the right cell by cell until you reach 23 at which point you go back to column A. That's the point of the mod() part. Every 23 cells, you go down one row off of A1. That's the point of the int() part.

To turn it into a macro, either you do a loop with a copy / paste transpose, or you just use the formula, as in

Dim lCellCount as long

LCellCount =cells(1,1).currentregion.cells.count
Worksheets.add
With Range("a1:a" & lCellCount )
.formular1c1="=OFFSET(Sheet1!r1c1, INT(ROW()/23),MOD(ROW()-1,22),1,1)"
.value=.value
End with

This counts the number of data cells, adds a worksheet, puts the formula in then pastes values.

Thomas
0
 
LVL 15

Author Comment

by:ericpete
ID: 39971341
Brad,

I'm getting a type mismatch when I run the macro at line 14.

v(k, 1) = vData(i, j)

Thomas,

Very slick. Took me a couple of minutes (it's been a long time since I played with modules, and those were all in Access), but it works exactly as advertised.

Thanks!!

ep
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 15

Author Closing Comment

by:ericpete
ID: 39971349
My apologies; the style sheet for the page didn't load, and I incorrectly closed this, so I used those magic powers EE has bestowed (guess the newsletter work comes in handy once in a while) and reopened it, then re-closed it.

Thanks to both of you for your kind assistance.

ep
0
 
LVL 80

Expert Comment

by:byundt
ID: 39971352
Eric,
Could you please post your workbook? The code is working using my sample data, but there may be something I hadn't anticipated with your actual data.

Brad
0
 
LVL 15

Author Comment

by:ericpete
ID: 39971397
Sure. This is what I received; it has no modules or macros attached. It's probably also recognizable to you, if not necessarily to Thomas... *laughing*
BradTest.xls
0
 
LVL 80

Expert Comment

by:byundt
ID: 39971417
Eric,
The earliest Excel on my computer is Excel 2003, which is very similar to Excel 2000 in terms of VBA code. The code runs without error on both Excel 2003 and 2013.

I don't know why my code generates an error on your computer.

Brad
0
 
LVL 15

Author Comment

by:ericpete
ID: 39971439
Brad,

It could quite easily be a problem that exists between the keyboard and the chair.

ep
0
 
LVL 15

Author Comment

by:ericpete
ID: 39971453
For the record, I was able to get Brad's code to work; I'm not sure what I did differently.

The major difference between Thomas' macro and Brad's is that Thomas' puts the data on a new worksheet, preserving the original -- which is kind of nice when you're not quite sure what you're doing.

ep
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now