How can I condense this code and also include line breaks please.

S.H.A.D.O.

Well-known Member
Joined
Sep 6, 2005
Messages
1,915
Good evening,

Is there any way that I can condense the code below and also include line breaks please.

Code:
Option Explicit
Option Base 1

Sub Convert()
    With Application
        .ScreenUpdating = False: .Calculation = xlCalculationManual: .DisplayAlerts = False
    End With

'   Convert values back to formulas.
    Range("J5").Formula = "=CONCATENATE(""1 = "",INDEX('Main Statistics'!B$7:B$53,MATCH(SMALL('Main Statistics'!S$7:S$53,1),'Main Statistics'!S$7:S$53,0)),"" ["",INDEX('Main Statistics'!M$7:M$53,MATCH(SMALL('Main Statistics'!S$7:S$53,1),'Main Statistics'!S$7:S$53,0)),""]"",)"
    Range("J6").Formula = "=CONCATENATE(""2 = "",INDEX('Main Statistics'!B$7:B$53,MATCH(SMALL('Main Statistics'!S$7:S$53,2),'Main Statistics'!S$7:S$53,0)),"" ["",INDEX('Main Statistics'!M$7:M$53,MATCH(SMALL('Main Statistics'!S$7:S$53,2),'Main Statistics'!S$7:S$53,0)),""]"",)"
    Range("J7").Formula = "=CONCATENATE(""3 = "",INDEX('Main Statistics'!B$7:B$53,MATCH(SMALL('Main Statistics'!S$7:S$53,3),'Main Statistics'!S$7:S$53,0)),"" ["",INDEX('Main Statistics'!M$7:M$53,MATCH(SMALL('Main Statistics'!S$7:S$53,3),'Main Statistics'!S$7:S$53,0)),""]"",)"
    Range("J8").Formula = "=CONCATENATE(""4 = "",INDEX('Main Statistics'!B$7:B$53,MATCH(SMALL('Main Statistics'!S$7:S$53,4),'Main Statistics'!S$7:S$53,0)),"" ["",INDEX('Main Statistics'!M$7:M$53,MATCH(SMALL('Main Statistics'!S$7:S$53,4),'Main Statistics'!S$7:S$53,0)),""]"",)"
    Range("J9").Formula = "=CONCATENATE(""5 = "",INDEX('Main Statistics'!B$7:B$53,MATCH(SMALL('Main Statistics'!S$7:S$53,5),'Main Statistics'!S$7:S$53,0)),"" ["",INDEX('Main Statistics'!M$7:M$53,MATCH(SMALL('Main Statistics'!S$7:S$53,5),'Main Statistics'!S$7:S$53,0)),""]"",)"
    Range("J10").Formula = "=CONCATENATE(""6 = "",INDEX('Main Statistics'!B$7:B$53,MATCH(SMALL('Main Statistics'!S$7:S$53,6),'Main Statistics'!S$7:S$53,0)),"" ["",INDEX('Main Statistics'!M$7:M$53,MATCH(SMALL('Main Statistics'!S$7:S$53,6),'Main Statistics'!S$7:S$53,0)),""]"",)"

    Range("J13").Formula = "=CONCATENATE(""1 = "",INDEX('Plus 1 Statistics'!B$7:B$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,1),'Plus 1 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 1 Statistics'!M$7:M$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,1),'Plus 1 Statistics'!S$7:S$53,0)),""]"",)"
    Range("J14").Formula = "=CONCATENATE(""2 = "",INDEX('Plus 1 Statistics'!B$7:B$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,2),'Plus 1 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 1 Statistics'!M$7:M$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,2),'Plus 1 Statistics'!S$7:S$53,0)),""]"",)"
    Range("J15").Formula = "=CONCATENATE(""3 = "",INDEX('Plus 1 Statistics'!B$7:B$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,3),'Plus 1 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 1 Statistics'!M$7:M$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,3),'Plus 1 Statistics'!S$7:S$53,0)),""]"",)"
    Range("J16").Formula = "=CONCATENATE(""4 = "",INDEX('Plus 1 Statistics'!B$7:B$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,4),'Plus 1 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 1 Statistics'!M$7:M$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,4),'Plus 1 Statistics'!S$7:S$53,0)),""]"",)"
    Range("J17").Formula = "=CONCATENATE(""5 = "",INDEX('Plus 1 Statistics'!B$7:B$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,5),'Plus 1 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 1 Statistics'!M$7:M$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,5),'Plus 1 Statistics'!S$7:S$53,0)),""]"",)"
    Range("J18").Formula = "=CONCATENATE(""6 = "",INDEX('Plus 1 Statistics'!B$7:B$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,6),'Plus 1 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 1 Statistics'!M$7:M$53,MATCH(SMALL('Plus 1 Statistics'!S$7:S$53,6),'Plus 1 Statistics'!S$7:S$53,0)),""]"",)"

    Range("J21").Formula = "=CONCATENATE(""1 = "",INDEX('Plus 2 Statistics'!B$7:B$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,1),'Plus 2 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 2 Statistics'!M$7:M$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,1),'Plus 2 Statistics'!S$7:S$53,0)),""]"",)"
    Range("J22").Formula = "=CONCATENATE(""2 = "",INDEX('Plus 2 Statistics'!B$7:B$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,2),'Plus 2 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 2 Statistics'!M$7:M$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,2),'Plus 2 Statistics'!S$7:S$53,0)),""]"",)"
    Range("J23").Formula = "=CONCATENATE(""3 = "",INDEX('Plus 2 Statistics'!B$7:B$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,3),'Plus 2 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 2 Statistics'!M$7:M$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,3),'Plus 2 Statistics'!S$7:S$53,0)),""]"",)"
    Range("J24").Formula = "=CONCATENATE(""4 = "",INDEX('Plus 2 Statistics'!B$7:B$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,4),'Plus 2 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 2 Statistics'!M$7:M$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,4),'Plus 2 Statistics'!S$7:S$53,0)),""]"",)"
    Range("J25").Formula = "=CONCATENATE(""5 = "",INDEX('Plus 2 Statistics'!B$7:B$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,5),'Plus 2 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 2 Statistics'!M$7:M$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,5),'Plus 2 Statistics'!S$7:S$53,0)),""]"",)"
    Range("J26").Formula = "=CONCATENATE(""6 = "",INDEX('Plus 2 Statistics'!B$7:B$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,6),'Plus 2 Statistics'!S$7:S$53,0)),"" ["",INDEX('Plus 2 Statistics'!M$7:M$53,MATCH(SMALL('Plus 2 Statistics'!S$7:S$53,6),'Plus 2 Statistics'!S$7:S$53,0)),""]"",)"

    With Application
        .DisplayAlerts = True: .Calculation = xlCalculationAutomatic: .ScreenUpdating = True
    End With
End Sub

Thanks very much in advance.
 
Sorry to trouble you again sheetspread, I can't seem to adapt your code to cater for the following.
This is the last bit I would like to be able to accomplish, but it is not a biggie if I can't.
I can't seem to be able to loop the formulas to go across but using data from cells that are going down.
Here is code that works anyway.
As I said, not a biggie if it can't be done.

Code:
Sub Convert()
    With Application
        .ScreenUpdating = False: .Calculation = xlCalculationManual: .DisplayAlerts = False
    End With

            Range("M8").Value = "=MID(J5,5,2)+0"
            Range("N8").Value = "=MID(J6,5,2)+0"
            Range("O8").Value = "=MID(J7,5,2)+0"
            Range("P8").Value = "=MID(J8,5,2)+0"
            Range("Q8").Value = "=MID(J9,5,2)+0"
            
            Range("M9").Value = "=MID(J13,5,2)+0"
            Range("N9").Value = "=MID(J14,5,2)+0"
            Range("O9").Value = "=MID(J15,5,2)+0"
            Range("P9").Value = "=MID(J16,5,2)+0"
            Range("Q9").Value = "=MID(J17,5,2)+0"
            Range("M10").Value = "=MID(J21,5,2)+0"
            Range("N10").Value = "=MID(J22,5,2)+0"
            Range("O10").Value = "=MID(J23,5,2)+0"
            Range("P10").Value = "=MID(J24,5,2)+0"
            Range("Q10").Value = "=MID(J25,5,2)+0"
            
    With Application
        .DisplayAlerts = True: .Calculation = xlCalculationAutomatic: .ScreenUpdating = True
    End With
End Sub

Thanks again for your help, time, and effort on this, it is appreciated.
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
This:

Code:
Sub test2()
Dim i%, j%
For i = 0 To 2
For j = 0 To 4
Cells(8 + i, 13 + j).Value = "=MID(J" & j + 5 + i * 8 & ",5,2)+0"
Next j
Next i
End Sub

?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,336
Messages
6,124,338
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top