Hello,
I am new to this service. I am hoping someone can help me with an issue I have been struggling with.
Attached is a sample dataset. Columns D through AG need to be arranged as individual records, but columns A through C need to follow each record as each row (as currently organized) is an event. I have tried all kinds of functions (transpose, index, match, offset, etc.), but this appears to be over my head.
Can someone help, please?
Thanks in advance!
SchoobsVT,
Welcome to the Excel Forum.
Can you add to your workbook a new worksheet with the new format you are looking for (say, for at least two records)?
Click on the New Post button, then scroll down and see Manage Attachments.
Have a great day,
Stan
stanleydgromjr
Windows Vista Business, Excel 2003 and 2007
If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
run the macro and it will reformat and place the data on sheet2
Hope this was useful or entertaining.
This should do it, it's not fast, but it does the work:
Option Explicit Sub RowFormatColumnData() Dim Faults As Range Dim LastRw As Long, Rw As Long Application.ScreenUpdating = False LastRw = Range("A" & Rows.Count).End(xlUp).Row For Rw = LastRw To 2 Step -1 Set Faults = Range(Cells(Rw, "D"), Cells(Rw, Columns.Count).End(xlToLeft)) If Faults.Cells.Count > 1 Then Range("D" & Rw + 1).Resize(Faults.Cells.Count - 1, 1).EntireRow.Insert xlShiftDown With Faults.Resize(1, Faults.Cells.Count - 1).Offset(0, 1) .Copy Range("D" & Rw + 1).PasteSpecial xlPasteAll, Transpose:=True .ClearContents End With End If Next Rw With Columns("A:C") .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C" .Value = .Value End With Range("E1", Range("E1").End(xlToRight)).Clear Range("D1") = "Fault" Range("A2").Select Range("A1").CurrentRegion.Columns.AutoFit ActiveWindow.FreezePanes = True Application.ScreenUpdating = True End Sub
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
tony h, you are a life saver! That bit of VBA is magical!
Quick follow-up question: Other than Excel's column and row limits, does this macro have any limits? For example, if I have 1000 rows (instead of just over 500) and 40 columns (instead of just over 30), will it still work, or do those parameters have to be set? Please excuse my lack of familiarity with VBA.
It works on the size of the used area of sheet1. So it readjusts to what you have got.
The only issue might be if your rows x columns was greater than the maximum size of a sheet.
PS the best way to say thanks is to click on the "scales" icon (next to the red triangle) on any post you find helpful.
Hope this was useful or entertaining.
i think its better to store the data in a variable, do the work and paste back onto sheet or you will be slowed down by Excel/ VBA interaction. If you have huge amounts of rows and columns its worth keeping this in mind.
See attached using this technique.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks