Forum Discussion
Liosnia
Jun 05, 2022Copper Contributor
Use VBA to autofill a range of row based on user input
Hello, I need help for this problem I want to make a visual basic modul that able to auto fill a triangle range of row with the data alfabet from a-z bassed on user input in inputbox. ...
- Jun 05, 2022
For example:
Sub CreateTriangle() Dim i As Long Dim j As Long Dim c As Long Dim n As Long n = Application.InputBox(Prompt:="How many rows do you want to fill?", Type:=1) If n < 1 Then Beep Exit Sub End If Application.ScreenUpdating = False c = 65 For i = 1 To n For j = 1 To i Cells(i + 1, j).Value = Chr(c) c = c + 1 If c > 90 Then c = 65 Next j Next i Application.ScreenUpdating = True End Sub
HansVogelaar
Jun 05, 2022MVP
For example:
Sub CreateTriangle()
Dim i As Long
Dim j As Long
Dim c As Long
Dim n As Long
n = Application.InputBox(Prompt:="How many rows do you want to fill?", Type:=1)
If n < 1 Then
Beep
Exit Sub
End If
Application.ScreenUpdating = False
c = 65
For i = 1 To n
For j = 1 To i
Cells(i + 1, j).Value = Chr(c)
c = c + 1
If c > 90 Then c = 65
Next j
Next i
Application.ScreenUpdating = True
End Sub
Liosnia
Jun 05, 2022Copper Contributor
This worked like a charm
Thanks so much for you assistance.
Thanks so much for you assistance.
- SergeiBaklanJun 05, 2022Diamond Contributor
- Subodh_Tiwari_sktneerJun 05, 2022Silver Contributor
Please take a minute to accept the post with the proposed solution as a Best Response to mark your question as Solved.