Maggie Barr
Board Regular
- Joined
- Jan 28, 2014
- Messages
- 188
Hello there,
I found an amazing macro on this forum by Hiker95 that works perfectly for me except that I would like for it to ignore blank cells within the dataset. I am using a PC with Excel 2010. When I run the macro it gives me what I want, but it also creates rows for cells within the spreadsheet that are blanks, and I would like for it to not create rows for the blank cells. In column A I have the current scientific Latin name of a plant, and in the subsequent columns (B-Q) I have Latin synonymy. I would like Column A to get repeated and Have columns B-Q get put in Column B with the heading of those columns in Column C (Please see sheet 2 of the Box Net file below for example). The Macro gave me Column A repeated to match the synonymy in Column B (from all the other columns), but there are many blanks.
So Sorry for not being able to display the data, I am new to all of this, and I have tried to post examples/screanshots of my data using MrExceHtml, but when I paste it, only a large amount of what look like garble is visible (hopefully I can figure this one out soon).
I have uploaded my file to Box Net: https://app.box.com/s/pdcvamsr9dtm8atsmz6d
In sheet one is the raw data, and in sheet two is the data after the macro was run.
In case the macro doesn't come through as visible in developer through Box Net the macro I ran is below:
Thank you all so much for your time and help, and sorry for my inabilities to post screenshots yet.
Best Wishes,
Maggie
I found an amazing macro on this forum by Hiker95 that works perfectly for me except that I would like for it to ignore blank cells within the dataset. I am using a PC with Excel 2010. When I run the macro it gives me what I want, but it also creates rows for cells within the spreadsheet that are blanks, and I would like for it to not create rows for the blank cells. In column A I have the current scientific Latin name of a plant, and in the subsequent columns (B-Q) I have Latin synonymy. I would like Column A to get repeated and Have columns B-Q get put in Column B with the heading of those columns in Column C (Please see sheet 2 of the Box Net file below for example). The Macro gave me Column A repeated to match the synonymy in Column B (from all the other columns), but there are many blanks.
So Sorry for not being able to display the data, I am new to all of this, and I have tried to post examples/screanshots of my data using MrExceHtml, but when I paste it, only a large amount of what look like garble is visible (hopefully I can figure this one out soon).
I have uploaded my file to Box Net: https://app.box.com/s/pdcvamsr9dtm8atsmz6d
In sheet one is the raw data, and in sheet two is the data after the macro was run.
In case the macro doesn't come through as visible in developer through Box Net the macro I ran is below:
Thank you all so much for your time and help, and sorry for my inabilities to post screenshots yet.
Best Wishes,
Maggie
Code:
Sub ReorgData()
' hiker95, 08/04/2014, ME796335
Dim w1 As Worksheet, w2 As Worksheet
Dim a As Variant, o As Variant
Dim i As Long, j As Long
Dim lr As Long, lc As Long, c As Long, n As Long
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
With w1
lr = .Cells(Rows.Count, 1).End(xlUp).Row
lc = .Cells(1, Columns.Count).End(xlToLeft).Column
a = .Range(.Cells(1, 1), .Cells(lr, lc))
n = ((lr - 1) * (lc - 1)) + 1
ReDim o(1 To n, 1 To 3)
End With
j = j + 1
o(j, 1) = "Name"
o(j, 2) = "value"
o(j, 3) = "Yr"
For i = 2 To lr
For c = 2 To lc
j = j + 1
o(j, 1) = a(i, 1)
o(j, 2) = a(i, c)
o(j, 3) = Right(a(1, c), Len(a(1, c)) - 2)
Next c
Next i
With w2
.UsedRange.ClearContents
.Cells(1, 1).Resize(n, 3).Value = o
.Columns(1).Resize(, 3).AutoFit
.Activate
End With
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: