0

I have a problem with my macro.. I have 2500 numbers and Id like to sort numbers like that: 1:10, next jump to 17, 17:48, jump to 50 and one again.. here is my code, I can find a mistake

Sub numeracja()
    Dim IleNaLiscie, licznik As Integer

    Sheets("sum").Select
    Range("L1").Activate
    IleNaLiscie = 0
    licznik = 1

    Do While licznik < 100
        Do While ActiveCell.Offset(IleNaLiscie, -10).Text <> ""   
            If IleNaLiscie < licznik * 10 Then
                Do While IleNaLiscie < licznik * 10
                    ActiveCell.Offset(IleNaLiscie, 0).Copy
                    ActiveCell.Offset(IleNaLiscie, -11).Select
                    ActiveSheet.Paste
                    Range("L1").Activate
                    IleNaLiscie = IleNaLiscie + 1
                Loop 
            Else
                IleNaLiscie = IleNaLiscie + 6 'HERE

                If IleNaLiscie < licznik * 48 Then    
                    Do While IleNaLiscie < licznik * 48
                        ActiveCell.Offset(IleNaLiscie, 0).Copy
                        ActiveCell.Offset((IleNaLiscie - 6), -11).Select
                        ActiveSheet.Paste
                        Range("L1").Activate
                        IleNaLiscie = IleNaLiscie + 1
                    Loop
                Else 
                    IleNaLiscie = IleNaLiscie + 2

                    If IleNaLiscie = licznik * 50 Then 'here "licznik" isn't increment but it goes to the 'HERE' 
                        licznik = licznik + 1
                    Else

                    End If
                End If
            End If
        Loop
    Loop
End Sub

and then all program isn't performed again.. Can you help me?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Kim
  • 25
  • 3
  • That doesn't look like sorting. Could you provide some more examples. – Profex Aug 02 '18 at 18:00
  • At a casual glance, I suspect you're getting an overflow error, in that `licznik` is declared as `Integer` and `IleNaLiscie` is implicitly `Variant`. – Comintern Aug 02 '18 at 18:04
  • To me, the code looks like it was recorded macro, with some `Do...Loop`s and `If`s added in to repeat steps in the sorting of a specific list. Please describe what is in Columns `A`, `B` & `L`. If it's just a sort that is needed, Excel has one build in. If you want a VBA sort, take a look [here](https://stackoverflow.com/questions/152319/vba-array-sort-function/). – Profex Aug 02 '18 at 18:42
  • Just a note: `Dim IleNaLiscie, licznik As Integer` declares `licznik` as type `Integer` but `IleNaLiscie` as type `Variant`. You need to specify a type for **every** variable: `Dim IleNaLiscie As Integer, licznik As Integer`. • Also this might help to improve your code: [How to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). – Pᴇʜ Aug 03 '18 at 06:08

0 Answers0