notarypublic
New Member
- Joined
- Nov 5, 2010
- Messages
- 13
Hello,
I'm working on a project that has data grouped first by one attribute, and then another: There are three tractors using a 335 HP engine, and each of them has their own column.
I've been working on a macro to condense those three columns into a single column, with the format as follows: "NH 335: N57-M24, N57-P16, N57-P16HD"
I'm trying to copy the data all into a new worksheet to make it easier to work with. I haven't worked with variable amounts of columns before (While a 335 HP engine has 3 models, a 440 HP engine could go in 5) which is what I think is causing the problem. Here's the macro I've written so far:
This populates a field with a part number, and another with a part description. It should then output a string similar to the desired one, but it hasn't output any results to speak of.
Any ideas?
I'm working on a project that has data grouped first by one attribute, and then another: There are three tractors using a 335 HP engine, and each of them has their own column.
I've been working on a macro to condense those three columns into a single column, with the format as follows: "NH 335: N57-M24, N57-P16, N57-P16HD"
I'm trying to copy the data all into a new worksheet to make it easier to work with. I haven't worked with variable amounts of columns before (While a 335 HP engine has 3 models, a 440 HP engine could go in 5) which is what I think is causing the problem. Here's the macro I've written so far:
Code:
Sub quickParse()
On Error GoTo oops
Dim partRangeStart As String, engineHP As String, columnOutput As String
Dim partRange As Integer
Dim i As Integer, j As Integer
engineHP = InputBox(prompt:="What tractor model is being condensed?", Title:="tractor model", Default:="NH 335")
partRangeStart = InputBox(prompt:="Please enter a Column to start condensing:", Title:="Engine HP", _
Default:="A")
partRange = InputBox(prompt:="How many columns are to be condensed?", Title:="How many models are in this series?", _
Default:="1")
columnOutput = InputBox(prompt:="Select a column to output to", Title:="Column to output to:", _
Default:="A")
'i is the loop for all the parts in the spreadsheet, j is the loop for the column range for each model series
i = 3
Do
Worksheets("PartList").Range("A" & i).Value = Worksheets("temp").Range("A" & i).Value
Worksheets("PartList").Range("B" & i).Value = Worksheets("temp").Range("B" & i).Value
'runs through the column range
j = 0
Worksheets("PartList").Range(columnOutput, i).Value = engineHP & ": "
Do
If Worksheets("temp").Range(partRangeStart + j, i).Value <> "" Then
Worksheets("PartList").Range(columnOutput, i).Value = Worksheets("PartList").Range(columnOutput, i).Value _
+ Worksheets("temp").Range(partRangeStart + j, i).Value & ", "
End If
Loop Until j = partRange - 1
i = i + 1
Loop Until Worksheets("temp").Range("A" & i).Value = ""
oops:
End Sub
This populates a field with a part number, and another with a part description. It should then output a string similar to the desired one, but it hasn't output any results to speak of.
Any ideas?