Application DisplayAlerts False If SheetExists Прибыльные места Then S

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Application.DisplayAlerts = False
If SheetExists("Прибыльные места") Then
Sheets("Прибыльные места").Delete
End If
Application.DisplayAlerts = True
' Declare WorkSheets
Set Income = Worksheets.Add
Income.Name = "Прибыльные места"
Set Trips = Worksheets("Стоимость командировок")
nRow_Trip = Trips.Cells(1, 1).CurrentRegion.Rows.Count
nCol_Trip = Trips.Cells(1, 1).CurrentRegion.Columns.Count
Trips.Range(Trips.Cells(2, 6), Trips.Cells(nRow_Trip, nCol_Trip)).Copy
Income.Range(Income.Cells(2, 1), Income.Cells(nRow_Trip + 1, nCol_Trip)).Select
Income.PasteSpecial
Income.Columns(2).Delete
Income.Columns(3).Delete
Income.Columns(4).Delete
Income.Columns("B").Delete
Income.Cells(1, 1) = "Название мест"
Income.Cells(1, 2) = "Доходность"
' Autosize sheets
Income.Rows(1).RowHeight = 25
Income.Rows(1).Interior.Color = RGB(205, 195, 255)
Income.Cells(1, 2).Interior.Color = RGB(255, 163, 83)
' Color border bottom
Income.Rows().EntireRow.Borders(xlEdgeTop).Weight = xlThick
Income.Rows(1).EntireColumn.AutoFit
nRow_Income = Income.Cells(1, 1).CurrentRegion.Rows.Count
nCol_Income = Income.Cells(1, 1).CurrentRegion.Columns.Count
Income.Range(Cells(1, 1), Cells(nRow_Income, nCol_Income)).Sort Key1:=Cells(1, 2), _
Order1:=xlDescending, Header:=xlGuess, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
For i = 2 To nRow_Income
If Income.Cells(i, 2) < 0 Then
Income.Cells(i, 2).Interior.Color = RGB(255, 94, 85)
End If
If Income.Cells(i, 2) > 0 And Income.Cells(i, 2) < 100000 Then
Income.Cells(i, 2).Interior.Color = RGB(255, 232, 150)
End If
If Income.Cells(i, 2) > 100000 Then
Income.Cells(i, 2).Interior.Color = RGB(171, 255, 75)
End If
Next