Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

inherited code

ResolvedVersion 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 courses

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

The dual nature of toolbar buttons

Many toolbar buttons are dual purpose, though the two purposes are often linked in some way. For example, Align Left aligns a cell's contents to the left of the cell. However, hold down Shift and press the Align Left button: Excel aligns the cell contents to the right.
You may respond: So what? Well, you can reduce the number of buttons on your toolbar to make your screen less cluttered and allow more room for, perhaps, some of your own commands. After all, what's the point of an Align Right button when Shift+Align Left does the same thing?

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.