davidplowman
New Member
- Joined
- Oct 31, 2013
- Messages
- 10
Hello:
I have an issue and I'm hoping someone can help me with.
I have a spreadsheet that's has 28 columns and more than 3,000 rows.
One of the columns is a year range (i.e. 2010-2013, 1988-1999, 1996-1998 or whatever).
The file has to be submitted to another department for an upload to a website, and each year has to be listed on a separate row, with all of the information remaining the same.
So in other words, a portion of my spreadsheet that looks like this:</SPAN>
[TABLE="width: 0"]
<TBODY>[TR]
[TD]Source</SPAN>
[/TD]
[TD]New PN (Main # to Search By)</SPAN>
[/TD]
[TD]Make</SPAN>
[/TD]
[TD]Vehicle Type</SPAN>
[/TD]
[TD]Year (From - To)</SPAN>
[/TD]
[TD]Model</SPAN>
[/TD]
[TD]Engine</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2010-2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2012-2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]HA</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]1999-2003</SPAN>
[/TD]
[TD]Various Models</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
Would ultimately look like this:</SPAN>
[TABLE="width: 0"]
<TBODY>[TR]
[TD]Source</SPAN>
[/TD]
[TD]New PN (Main # to Search By)</SPAN>
[/TD]
[TD]Make</SPAN>
[/TD]
[TD]Vehicle Type</SPAN>
[/TD]
[TD]Year (From - To)</SPAN>
[/TD]
[TD]Model</SPAN>
[/TD]
[TD]Engine</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2010</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2011</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2012</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]HA</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]HA</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
Would ultimately look like this:</SPAN>
[TABLE="width: 0"]
<TBODY>[TR]
[TD]Source</SPAN>
[/TD]
[TD]New PN (Main # to Search By)</SPAN>
[/TD]
[TD]Make</SPAN>
[/TD]
[TD]Vehicle Type</SPAN>
[/TD]
[TD]Year (From - To)</SPAN>
[/TD]
[TD]Model</SPAN>
[/TD]
[TD]Engine</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2010</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2011</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2012</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]HA</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]HA</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
Someone suggested I try the following VBA program:</SPAN>
1. Sub SplitDataByYears()</SPAN>
2. Dim R As Long, C As Long, CC As Long, Index As Long, TotalYears As Long, LastRow As Long</SPAN>
3. Dim YearCol As Long, ArrIn As Variant, ArrOut As Variant</SPAN>
4. Const YearLetter As String = "f"</SPAN>
5. YearCol = Cells(1, YearLetter).Column</SPAN>
6. LastRow = Cells(Rows.Count, YearCol).End(xlUp).Row</SPAN>
7. ArrIn = Range("A1:AB" & LastRow)</SPAN>
8. TotalYears = 1 + Evaluate("SUMPRODUCT(ISNUMBER(FIND(""-""," & YearLetter & "2:" & YearLetter & _</SPAN>
9. LastRow & "))*(1+RIGHT(" & YearLetter & "2:" & YearLetter & LastRow & _</SPAN>
10. ",4)-LEFT(" & YearLetter & "2:" & YearLetter & LastRow & ",4)))")</SPAN>
11. ReDim ArrOut(1 To TotalYears, 1 To 28)</SPAN>
12. For R = 2 To UBound(ArrIn)</SPAN>
13. For CC = CLng(Left(ArrIn(R, YearCol), 4)) To CLng(Right(ArrIn(R, YearCol), 4))</SPAN>
14. Index = Index + 1</SPAN>
15. For C = 1 To 28</SPAN>
16. If C = YearCol Then</SPAN>
17. ArrOut(Index, C) = CC</SPAN>
18. Else</SPAN>
19. ArrOut(Index, C) = ArrIn(R, C)</SPAN>
20. End If</SPAN>
21. Next</SPAN>
22. Next</SPAN>
23. Next</SPAN>
24. With Sheets("Sheet2")</SPAN>
25. .Range("A1:AB1") = ActiveSheet.Range("A1:AB1").Value</SPAN>
26. .Range("A2:AB" & UBound(ArrOut) + 1) = ArrOut</SPAN>
27. End With</SPAN>
Unfortunately, I’ve never used VBA, and can’t seem to get off the ground on this. I receive an error that reads “Compile error: Expected line number or statement or end of statement.”</SPAN>
Could anyone help me decode this error and advise how I can fix it?</SPAN>
Also, could someone guide me to a good beginners guide to VBA, all of this is so new to me that I don’t know where to begin troubleshooting something when I get an error.</SPAN>
Thank you,</SPAN>
David</SPAN>
I have an issue and I'm hoping someone can help me with.
I have a spreadsheet that's has 28 columns and more than 3,000 rows.
One of the columns is a year range (i.e. 2010-2013, 1988-1999, 1996-1998 or whatever).
The file has to be submitted to another department for an upload to a website, and each year has to be listed on a separate row, with all of the information remaining the same.
So in other words, a portion of my spreadsheet that looks like this:</SPAN>
[TABLE="width: 0"]
<TBODY>[TR]
[TD]Source</SPAN>
[/TD]
[TD]New PN (Main # to Search By)</SPAN>
[/TD]
[TD]Make</SPAN>
[/TD]
[TD]Vehicle Type</SPAN>
[/TD]
[TD]Year (From - To)</SPAN>
[/TD]
[TD]Model</SPAN>
[/TD]
[TD]Engine</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2010-2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2012-2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]HA</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]1999-2003</SPAN>
[/TD]
[TD]Various Models</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
Would ultimately look like this:</SPAN>
[TABLE="width: 0"]
<TBODY>[TR]
[TD]Source</SPAN>
[/TD]
[TD]New PN (Main # to Search By)</SPAN>
[/TD]
[TD]Make</SPAN>
[/TD]
[TD]Vehicle Type</SPAN>
[/TD]
[TD]Year (From - To)</SPAN>
[/TD]
[TD]Model</SPAN>
[/TD]
[TD]Engine</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2010</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2011</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2012</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]HA</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]HA</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
Would ultimately look like this:</SPAN>
[TABLE="width: 0"]
<TBODY>[TR]
[TD]Source</SPAN>
[/TD]
[TD]New PN (Main # to Search By)</SPAN>
[/TD]
[TD]Make</SPAN>
[/TD]
[TD]Vehicle Type</SPAN>
[/TD]
[TD]Year (From - To)</SPAN>
[/TD]
[TD]Model</SPAN>
[/TD]
[TD]Engine</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2010</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2011</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]FE</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2012</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]HA</SPAN>
[/TD]
[/TR]
[TR]
[TD]Lester</SPAN>
[/TD]
[TD]A7T03277A</SPAN>
[/TD]
[TD]Hyster</SPAN>
[/TD]
[TD]Lift Truck</SPAN>
[/TD]
[TD]2013</SPAN>
[/TD]
[TD]DB</SPAN>
[/TD]
[TD]HA</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
Someone suggested I try the following VBA program:</SPAN>
1. Sub SplitDataByYears()</SPAN>
2. Dim R As Long, C As Long, CC As Long, Index As Long, TotalYears As Long, LastRow As Long</SPAN>
3. Dim YearCol As Long, ArrIn As Variant, ArrOut As Variant</SPAN>
4. Const YearLetter As String = "f"</SPAN>
5. YearCol = Cells(1, YearLetter).Column</SPAN>
6. LastRow = Cells(Rows.Count, YearCol).End(xlUp).Row</SPAN>
7. ArrIn = Range("A1:AB" & LastRow)</SPAN>
8. TotalYears = 1 + Evaluate("SUMPRODUCT(ISNUMBER(FIND(""-""," & YearLetter & "2:" & YearLetter & _</SPAN>
9. LastRow & "))*(1+RIGHT(" & YearLetter & "2:" & YearLetter & LastRow & _</SPAN>
10. ",4)-LEFT(" & YearLetter & "2:" & YearLetter & LastRow & ",4)))")</SPAN>
11. ReDim ArrOut(1 To TotalYears, 1 To 28)</SPAN>
12. For R = 2 To UBound(ArrIn)</SPAN>
13. For CC = CLng(Left(ArrIn(R, YearCol), 4)) To CLng(Right(ArrIn(R, YearCol), 4))</SPAN>
14. Index = Index + 1</SPAN>
15. For C = 1 To 28</SPAN>
16. If C = YearCol Then</SPAN>
17. ArrOut(Index, C) = CC</SPAN>
18. Else</SPAN>
19. ArrOut(Index, C) = ArrIn(R, C)</SPAN>
20. End If</SPAN>
21. Next</SPAN>
22. Next</SPAN>
23. Next</SPAN>
24. With Sheets("Sheet2")</SPAN>
25. .Range("A1:AB1") = ActiveSheet.Range("A1:AB1").Value</SPAN>
26. .Range("A2:AB" & UBound(ArrOut) + 1) = ArrOut</SPAN>
27. End With</SPAN>
Unfortunately, I’ve never used VBA, and can’t seem to get off the ground on this. I receive an error that reads “Compile error: Expected line number or statement or end of statement.”</SPAN>
Could anyone help me decode this error and advise how I can fix it?</SPAN>
Also, could someone guide me to a good beginners guide to VBA, all of this is so new to me that I don’t know where to begin troubleshooting something when I get an error.</SPAN>
Thank you,</SPAN>
David</SPAN>