98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Cannibalising code
Cannibalising code
Resolved · Low Priority · Version 2000
Cannibalising code
Hi there,
We've received this macro from another Local Authority, that automaticaly formats an excel/csv exported reports from a cr*p Capita-made database.
The report comes out of the database in excel as one long unformatted list, the below code sorts it out into a proper data table.
We would like to tweak the below code so it works with a range of other very similar reports from the same database. However the below code hasn't got many comments so we are a bit confused and would appreciate any pointers.
Cheers
Gareth Thomas
LB Merton
Sub converterThing()
Dim eof As Long
Dim i As Long, start As Long, finish As Long, j As Long
Dim currCode As String
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With ActiveWorkbook.ActiveSheet
' Add column for living in code
.Range("A1").EntireColumn.Insert xlShiftToRight
'where the data ends
eof = .Range("b65536").End(xlUp).Row
'Find first Living in
For i = 1 To eof Step 1
'Get the code
If Left(.Cells(i, 2), 10) & "" = "Living in:" Then
'found the living in:
'get code
currCode = Mid(.Cells(i, 2), 12, Len(.Cells(i, 2)))
start = i + 3
For j = i + 3 To eof Step 1
If Left(.Cells(j, 2), 6) = "Settin" Then
'End is found
finish = j - 1
Exit For
End If
Next j
.Range(.Cells(start, 1), .Cells(finish, 1)) = currCode
i = j - 1
End If
Next i
For i = 1 To eof Step 1
If .Cells(i, 2) = "Name" Then
'found the first row
.AutoFilterMode = False
.Range(.Cells(i, 1), .Cells(eof, 10)).AutoFilter 1, "="
.Range(.Cells(i + 1, 1), .Cells(eof + 1, 1)).EntireRow.Delete
.AutoFilterMode = False
.Range(.Cells(10, 1), .Cells(11, 1)).EntireRow.Delete
.Cells(10, 1) = "Living In"
Exit For
End If
Next i
.Cells.Columns.AutoFit
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
RE: Cannibalising code
Hi Gareth
Thanks for your post and the included code. This sort of thing does go beyond the scope of this forum however I know of just the person to check on this with. They are on holiday this week back in next week.
I will ask them to review what you have posted and if we can help then we will let you know what we need, the amount of time required and any related costs.
Kind regards
Jacob
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Turn Function tooltips on and offExcel 2002 (XP) and Excel 2003 have the Function tooltips facility. When you type in a function name followed by a bracket, for example, =IF(, a yellow box appears beside the function name and lists the function's arguments. This is very useful when you can't quite remember the order of a function's arguments or what the arguments actually are! |