VBA Code for Printing Different types of Pyramid using for Loop.
Автор: VBA Learning tutorials
Загружено: 2020-04-26
Просмотров: 266
Описание:
Please find the below mentioned code :-
Sub PrintStar1()
Dim i As Integer
For i = 1 To 10
Sheet1.Range("A" & i).Value = WorksheetFunction.Rept("*", i)
Next i
End Sub
Sub PrintStar2()
Dim i As Integer
For i = 10 To 1 Step -1
Sheet1.Range("B" & 11 - i).Value = WorksheetFunction.Rept("*", i)
Next i
End Sub
Sub PrintStar3()
Dim r As Integer
Dim c As Integer
For r = 1 To 5
For c = 1 To r
Sheet1.Range("F1").Cells(r, c).Value = "*"
Next c
Next r
End Sub
Sub PrintStar4()
Dim r As Integer
Dim c As Integer
Dim a As Integer
a = 5
For r = 1 To 5
For c = 1 To a
Sheet1.Range("F9").Cells(r, c).Value = "*"
Next c
a = a - 1
Next r
End Sub
Sub PrintStar5()
Dim r As Integer
Dim c As Integer
ActiveCell.Select
For r = 0 To 5
For c = 0 To r
ActiveCell.Offset(r, -c).Value = "*"
ActiveCell.Offset(r, c).Value = "*"
Next c
Next r
End Sub
Sub printStar6()
Dim r As Integer
Dim c As Integer
Dim a As Integer
a = 5
ActiveCell.Select
For r = 0 To 5
For c = 0 To a
ActiveCell.Offset(r, -c).Value = "*"
ActiveCell.Offset(r, c).Value = "*"
Next c
a = a - 1
Next r
End Sub
Sub PrintStar1()
Dim i As Integer
For i = 1 To 10
Sheet1.Range("A" & i).Value = WorksheetFunction.Rept("*", i)
Next i
End Sub
Sub PrintStar2()
Dim i As Integer
For i = 10 To 1 Step -1
Sheet1.Range("B" & 11 - i).Value = WorksheetFunction.Rept("*", i)
Next i
End Sub
Sub PrintStar3()
Dim r As Integer
Dim c As Integer
For r = 1 To 5
For c = 1 To r
Sheet1.Range("F1").Cells(r, c).Value = "*"
Next c
Next r
End Sub
Sub PrintStar4()
Dim r As Integer
Dim c As Integer
Dim a As Integer
a = 5
For r = 1 To 5
For c = 1 To a
Sheet1.Range("F9").Cells(r, c).Value = "*"
Next c
a = a - 1
Next r
End Sub
Sub PrintStar5()
Dim r As Integer
Dim c As Integer
ActiveCell.Select
For r = 0 To 5
For c = 0 To r
ActiveCell.Offset(r, -c).Value = "*"
ActiveCell.Offset(r, c).Value = "*"
Next c
Next r
End Sub
Sub printStar6()
Dim r As Integer
Dim c As Integer
Dim a As Integer
a = 5
ActiveCell.Select
For r = 0 To 5
For c = 0 To a
ActiveCell.Offset(r, -c).Value = "*"
ActiveCell.Offset(r, c).Value = "*"
Next c
a = a - 1
Next r
End Sub
Повторяем попытку...

Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: