Hi
I have minimal experience in writing macros in VBA, but was wondering if someone could please help me.
I have data extracted out of a finincial system where the long text firld is broken over many lines. Each unique combination in columns A, B, and C should have column D concatenated and the orginial lines deleted. I have 25,000 lines, and will do so each quarter.
I would really appreciate some help - I have tried to leverage off other solutions in the forum, but my VBA knowledge is so poor, I am unable to get them working.
Attached is a sample of how the data currently looks is in my post below.
Thanks!
Last edited by samford; 08-03-2010 at 12:26 AM.
Hi samford
Welcome to the forum
You would do best to post a sample workbook showing Before and After.
It should clearly illustrate your problem and not contain any sensitive data.
Cheers
Thanks Marcol
I have attached an example of the original post.
Cheers
Last edited by samford; 08-02-2010 at 11:12 PM.
Here is some basic code - not clear from the sample if Line Item & Text Identifier also need to be considered or not ?
(below assumes data sorted by PO number and Text Description per the sample)
Working example attached.Sub Example() Dim wsBefore As Worksheet, wsAfter As Worksheet Dim vText As Variant Dim lngPO As Long, lngRow As Long, lngLast As Long Dim xlCalc As XlCalculation On Error GoTo Handler With Application xlCalc = .Calculation .ScreenUpdating = False .Calculation = xlCalculationManual .EnableEvents = False End With Set wsBefore = Sheets("Before") Set wsAfter = Sheets.Add With wsAfter .Name = "After_" & Format(Now(), "ddmmyyhhmmss") .Range("A1:E1").Value = wsBefore.Range("A1:E1").Value End With With wsBefore For lngRow = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row lngPO = CLng(.Cells(lngRow, "A").Value) If lngPO > 0 Then If InStr(1, .Cells(lngRow, "D"), "Header Note", vbTextCompare) Then lngLast = lngRow Else lngLast = Application.WorksheetFunction.Match(lngPO, .Columns(1)) End If With .Range(.Cells(lngRow, "E"), .Cells(lngLast, "E")) vText = .Parent.Evaluate("TRANSPOSE(IF(ROW(" & .Address & ")," & .Address & "))") End With With wsAfter With .Cells(.Rows.Count, "A").End(xlUp).Offset(1) .Resize(, 4).Value = wsBefore.Cells(lngRow, "A").Resize(, 4).Value .Offset(, 4).Value = Join(vText, " ") End With End With lngRow = lngLast End If Next lngRow End With wsAfter.Columns("A:E").AutoFit ExitPoint: Set wsBefore = Nothing Set wsAfter = Nothing With Application .ScreenUpdating = True .Calculation = xlCalc .EnableEvents = True End With On Error GoTo 0 Exit Sub Handler: MsgBox "Error " & Err.Number & " (" & Err.Description & ")" Resume ExitPoint End Sub
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Thanks DonkeyOte.
Sorry to be a pain, but now I get an error: "Error 9 (subscript out of range)"
Am I missing something?
Are you referring to the sample file or your own file ?
Note in the sample file wsBefore is specified as being named "Before" - modify as appropriate.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
sorry - that was an obvious one, should've got that.
So now, it gets half way through and gives me another error "Error 13 (Type mismatch)".
I should point out (incase its important) that some Long text fields have blanks.
Thanks!
It would perhaps be an idea to post a sample that generates the specified error.
edit: I suspect you may have underlying error values in your long text data set ...
Last edited by DonkeyOte; 08-03-2010 at 03:19 AM.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
DonkeyOte
All sorted, an "=" sign had come through in one of the field from the database, so excel was expecting a formula. Once the "=" was deleted, your macro worked like a charm.
Thanks for taking the time to assist.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks