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.
for example:
the user will be asked how many row that want to be filled
if user input 4
then
the output on sheet will be
Thank you very much in advance,
Tania
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
4 Replies
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
- LiosniaCopper ContributorThis worked like a charm
Thanks so much for you assistance.- SergeiBaklanDiamond Contributor