Witam. Mam do oprogramowania choineczkę w VBA. Ogólnie wszystko póki co działa, tylko strasznie mi "mulić" zaczyna. Może ktoś doradzić co zrobić, aby mój skrypt przyspieszył, bo chcę dodać jeszcze parę rzeczy, a w takiej sytuacji, to excel mi się zaraz zawiesi i nic już nie dodam do skryptu.
Z góry przepraszam, jeżeli kaleczę ten język programowania.
Dim i, j, n, k, l, m As Integer
Dim shp As Shape
l = 23
n = 23
'Noc---------------------------------------------------------------------------
For i = 1 To n + 2
For j = 1 To n + 30
Arkusz5.Cells(i, j).Interior.Color = RGB(0, 0, 0)
'Gwiazdy-------------------------------------------------------------------
Randomize
A = Int(Rnd * (i - 1) + 1)
B = Int(Rnd * (4 - 1) + 1)
If A = 1 Then
If B = 1 Then Arkusz5.Cells(i, j) = "*"
End If
'--------------------------------------------------------------------------
Arkusz5.Cells.Font.Color = rgbWhite
Next j
Next i
'------------------------------------------------------------------------------
'Choinka-----------------------------------------------------------------------
For i = 1 To n
n = i
k = 23 - i
'm = Second(Time())
For j = 1 To n
Arkusz5.Cells(i, j).Interior.Color = RGB(11, 146, 54)
Range("q1").FormulaLocal = m
'Bombki----------------------------------------------------------------
Randomize
A = Int(Rnd * (i - 1) + 1) Mod n
B = Int(Rnd * (4 - 1) + 1)
If A = 1 Then
If B = 1 Then Arkusz5.Cells(i, j).Interior.Color = RGB(255, 0, 0)
If B = 2 Then Arkusz5.Cells(i, j).Interior.Color = RGB(60, 60, 240)
If B = 3 Then Arkusz5.Cells(i, j).Interior.Color = RGB(220, 70, 200)
If B = 4 Then Arkusz5.Cells(i, j).Interior.Color = RGB(150, 130, 190)
'End of bombki---------------------------------------------------------
End If
Next j
For j = 1 To k
'Funkcja zamalowująca część ekranu na czarno----------------------------
Arkusz5.Cells(i, j).Interior.Color = RGB(0, 0, 0)
'End-------------------------------------------------------------------
Next j
Next i
'------------------------------------------------------------------------------
'Korzeń------------------------------------------------------------------------
For i = n + 1 To n + 2
For j = (l - 1) / 2 To (l + 3) / 2
Arkusz5.Cells(i, j).Interior.Color = RGB(255, 255, 255)
Arkusz5.Cells(i, j).Interior.Color = RGB(70, 40, 10)
Arkusz5.Cells(i, j) = "||"
Next j
Next i
'------------------------------------------------------------------------------
'Gwiazda-----------------------------------------------------------------------
Set shp = Arkusz5.Shapes.AddShape(msoShape5pointStar, 515, 70, 70, 120)
With shp
.Fill.ForeColor.RGB = RGB(255, 255, 0)
.Name = "ButtonHide"
End With
'------------------------------------------------------------------------------
End Sub
Private Sub CommandButton2_Click()
'Zamalowywanie na biało wybranego obszaru--------------------------------------
For i = 1 To 50
For j = 1 To 50
Arkusz5.Cells(i, j).Interior.Color = RGB(255, 255, 255)
Next j
Next i
'------------------------------------------------------------------------------
'Usuwanie gwiazdy--------------------------------------------------------------
Dim shp As Shape
For Each shp In Arkusz5.Shapes
If shp.Name = "ButtonHide" Then
shp.Delete
End If
Next shp
'------------------------------------------------------------------------------
'Usuwanie tekstu---------------------------------------------------------------
Dim rng As Range
For Each rng In Range("A1:AC40")
rng = Replace(rng, "*", "")
rng = Replace(rng, "|", "")
Next rng
'------------------------------------------------------------------------------
End Sub