Загрузка данных


Sub DoEverything()

    Dim ws As Worksheet
    Dim lastRow As Long
    Dim r As Long

    Set ws = ActiveSheet

    ' Данные находятся в строках 16–23
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    ' Veloitus = ostettu määrä × a-hinta + pienlähetyslisä
    For r = 16 To lastRow
        ws.Cells(r, "D").Value = ws.Cells(r, "B").Value * ws.Cells(r, "C").Value + ws.Range("B11").Value
    Next r

    ' Формат €
    ws.Range("C16:D" & lastRow).NumberFormat = "0.00 €"

    ' Сортировка всей таблицы по a-hinta
    With ws.Sort
        .SortFields.Clear
        .SortFields.Add Key:=ws.Range("C16:C" & lastRow), _
            SortOn:=xlSortOnValues, _
            Order:=xlAscending, _
            DataOption:=xlSortNormal

        .SetRange ws.Range("A15:D" & lastRow)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .Apply
    End With

    MsgBox "Valmis! Taulukko laskettu ja lajiteltu.", vbInformation

End Sub