Help with assessment

User avatar
Leif
Administrator
Posts: 7208
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Help with assessment

Post by Leif »

3liiq8z wrote:
06 Aug 2020, 08:44
But don't know what to do!!!
Have you tried Googling for "excel vba using functions in code"?

You will get plenty of results, such as
Excel VBA Function and Sub - Easy Excel Macros
and
VBA VLOOKUP: How to Use Worksheet Functions in VBA [2020]
and
Excel VBA Function Tutorial: Return, Call, Examples
etc.
Leif

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with assessment

Post by HansV »

You can use it like this:

Code: Select all

    lastname = InputBox("Enter last name")
    If Not IsAlpha(lastname) Then
        MsgBox "lastname should only contain letters!"
        Exit Sub
    End If
but strictly speaking, point b) of the assignment asks you to use Do ... Loop. This clever function avoids the use of Do ... Loop.
Best wishes,
Hans

3liiq8z
NewLounger
Posts: 15
Joined: 05 Aug 2020, 20:14

Re: Help with assessment

Post by 3liiq8z »

Thanks. I am limited to using Do ..Loop

3liiq8z
NewLounger
Posts: 15
Joined: 05 Aug 2020, 20:14

Re: Help with assessment

Post by 3liiq8z »

Someone has helped me with this. Is that correct?

Code: Select all

Sub Test()
    Dim lastname, firstname, initial
    
    Do
        lastname = InputBox("Enter last name")
    Loop Until IsAlpha(lastname)
    
    Do
        firstname = InputBox("Enter first name")
    Loop Until IsAlpha(firstname)
    
    initial = InputBox("Enter initial")
    
    
End Sub

Function IsAlpha(s) As Boolean
    IsAlpha = Len(s) And Not s Like "*[!a-zA-Z]*"
End Function
Last edited by 3liiq8z on 06 Aug 2020, 10:33, edited 1 time in total.

3liiq8z
NewLounger
Posts: 15
Joined: 05 Aug 2020, 20:14

Re: Help with assessment

Post by 3liiq8z »

How can put the code as you did HansV in your last post?

User avatar
Leif
Administrator
Posts: 7208
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Help with assessment

Post by Leif »

3liiq8z wrote:
06 Aug 2020, 10:24
How can put the code as you did HansV in your last post?
Use the Code tags:
_
x.jpg

Example:
[code]
your code here...
[/code]
You do not have the required permissions to view the files attached to this post.
Leif

3liiq8z
NewLounger
Posts: 15
Joined: 05 Aug 2020, 20:14

Re: Help with assessment

Post by 3liiq8z »

Thanks a lot Leif. I edited my post.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with assessment

Post by HansV »

That should work, but it doesn't use Do ... Loop.
Best wishes,
Hans