Hottest Fudge
New Member
- Joined
- Oct 17, 2014
- Messages
- 16
Background: At current I am working on a extremely user friendly database for old people. They input data into a "master database" then excel pulls out information from this database to create various information sheets that can be printed off.
To input/update data I am attempting to use VBA (first time). At current I have set up a few question that the operator will be asked to enter upon pressing a button. The code at present does what it is intended to but I would like remove the go to line 10 function as I have heard this is bad practice. Is there any other way of doing this? Perhaps loops and stuff, but I am very new to this so an explanation/link to explanation would be very well received.
Thank you for reading!
Cheers,
Hottest Fudge
To input/update data I am attempting to use VBA (first time). At current I have set up a few question that the operator will be asked to enter upon pressing a button. The code at present does what it is intended to but I would like remove the go to line 10 function as I have heard this is bad practice. Is there any other way of doing this? Perhaps loops and stuff, but I am very new to this so an explanation/link to explanation would be very well received.
Thank you for reading!
Cheers,
Hottest Fudge
Code:
Sub NewSubstance()
Sheets("Input Sheet").Select
Dim reFerence As String
Dim NewRow As Variant
Dim Material As String
NewRow = Range("A1").End(xlDown).Row + 1
10: Material = InputBox("What is the name of the substance? ", , ("e.g. Dissolved Actylene"))
Range("B" & NewRow).Value = Material
If Len(Material) = 0 Or Material = ("e.g. Dissolved Actylene") Then
Range("B" & NewRow).Value = ("")
Exit Sub
End If
reFerence = InputBox(" What is the reference number of this substance? ", , ("e.g. AER_....."))
Range("A" & NewRow).Value = reFerence
If Len(reFerence) = 0 Or reFerence = ("e.g. AER_.....") Then
Range("A" & NewRow).Value = ("")
Exit Sub
End If
If reFerence = ("back") Then
Range("A" & NewRow).Value = ("")
GoTo 10
End If
End Sub
Last edited by a moderator: