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 » Inherited Code
Inherited Code
Resolved · Low Priority · Version 2003
Christian has attended:
Excel VBA Intro Intermediate course
Inherited 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
Christian Browning
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: Inherited Code
Hi Christian
Thanks for your post and appreciate the challenges you are having.
We may be able to assist however we would need to have a sample of the files you are using so that we can see how this code works. Furthermore a list highlighting what tweaks you wish to make to the code.
We can then get back to you and if we can help, we will relate the time required, completion time and costs.
If you wish to progress this please contact me direct.
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:3D formulas find and replaceAfter you know all the components of a 3D reference, you can change them to suit by using a localised Find and replace crt+f, if need be. |