Forum Discussion
blackwelldanny
May 03, 2018Copper Contributor
Create a pop up box for user data input that auto formulates specific cells
For Excel 2010, I have two columns created for counting. One counts up to a number and the other column counts backwards from that number to 1. Ex. First column counts up to 50 and the second colum...
blackwelldanny
May 03, 2018Copper Contributor
Nevermind I figured it out. I just changed the offset 1 value in "scell.Offset(r2, 1).Value = counter2" to however many columns I needed it to move over. Thanks again so much for your help. You're awesome!
Haytham Amairah
May 04, 2018Silver Contributor
Hi,
Nice to see you figured it out!
However, I've updated the code with an error handler to catch any error that may occur and prevent it from appearing so that it does not bother the end user.
This is the updated version:
Sub Workbook_Open()
'Written by Haytham Amairah
'Created: 5/3/2018
'Last updated: 5/4/2018
On Error GoTo handler
Dim number As Integer
number = Application.InputBox("Please enter a number:")
If number = False Then Exit Sub
Dim scell As Range
Set scell = Application.InputBox("Please select the starting cell:", , , , , , , 8)
For counter1 = 1 To number
Dim r1 As Integer
r1 = counter1 - 1
scell.Offset(r1).Value = counter1
Next counter1
For counter2 = number To 1 Step -1
Dim r2 As Integer
r2 = Abs(counter2 - number)
scell.Offset(r2, 2).Value = counter2
Next counter2
handler:
End Sub
Regards