Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loops in excel

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hello, i was wondering if someone could help me.
i currently have the user entering a name into an input box, and it works as if a value is entered it will say "you must enter a name", or if a name has been given then it eill go on to ask address. Basically this is what i have as part of the full macro:

Sub CustomerDetails()
Dim Name As String
Dim AddressLine1 As String
Dim AddressLine2 As String
Dim Town As String
Dim County As String
Dim PostCode As String

Name = InputBox("Please enter name in Title/Initial/Surname format")
If Name <> &quot;&quot; Then
Range(&quot;A3&quot;).Select
ActiveCell.Value = Name
Else
MsgBox &quot;You MUST Enter The Customer's Name&quot;
End If

AddressLine1 = InputBox(&quot;Please enter Address Line 1&quot;)
If AddressLine1 <> &quot;&quot; Then
Range(&quot;A6&quot;).Select
ActiveCell.Value = AddressLine1
Else
MsgBox &quot;You MUST Enter Address Line 1&quot;
End If

however i want to modify this so that if nothing is entered i want it to re-ask the user to enter a name or address or whatever. can someone please help me.

cheers

 
Try the following with the additional lines of code in bold, but consider a Userform :

Dim Name As String
Dim AddressLine1 As String
Dim AddressLine2 As String
Dim Town As String
Dim County As String
Dim PostCode As String
Dim Complete As Boolean
Complete = False
Do While Not Complete

Name = InputBox(&quot;Please enter name in Title/Initial/Surname format&quot;)
If Name <> &quot;&quot; Then
Range(&quot;A3&quot;).Select
ActiveCell.Value = Name
Complete = True
Else
MsgBox &quot;You MUST Enter The Customer's Name&quot;
End If
Loop
Complete = False
Do While Not Complete

AddressLine1 = InputBox(&quot;Please enter Address Line 1&quot;)
If AddressLine1 <> &quot;&quot; Then
Range(&quot;A6&quot;).Select
ActiveCell.Value = AddressLine1
Complete = True
Else
MsgBox &quot;You MUST Enter Address Line 1&quot;
End If
Loop

A.C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top