×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Macro to name project

Macro to name project

Macro to name project

(OP)
Is there a way to write a macro to prompt user to key in...say the project title and its client's name and automatically puts the answer to cell A1 and B1 respectively? If the cell A1 and B1 is already filled, the macro automatically writes the answer to the following cell (i.e A2 and B2). I'd written something like this but i would like the macro to loop back to the 1st question insstead of continuing to the 2nd, any help?

Sub Macro1()
Message1 = "Enter project title"
Title1 = "Project info"
Message2 = "Enter client's name"
Title2 = "Client info"
answer1 = InputBox(Message1, Title1, "")
answer2 = InputBox(Message2, Title2, "")
    If answer1 = Empty Then
        MsgBox Prompt:="You must enter a value."
        answer1 = InputBox(Message1, Title1, "")
    Else
    Range("A1") = answer1
    End If
    If answer2 = Empty Then
        MsgBox Prompt:="You must enter a value."
    Else
    Range("B1") = answer2
    End If
End Sub

RE: Macro to name project

Try this:

Sub Macro1()
Dim answer1 As String
Dim answer2 As String

Message1 = "Enter project title"
Title1 = "Project info"
Message2 = "Enter client's name"
Title2 = "Client info"
answer1 = ""
answer2 = ""

Do
    answer1 = InputBox(Message1, Title1, answer1)
Loop Until Len(answer1)
Range("A1") = answer1

Do
    answer2 = InputBox(Message2, Title2, answer2)
Loop Until Len(answer2)
Range("B1") = answer2


End Sub

good luck,
killswitch

RE: Macro to name project

(OP)
Thanks, it does work...

RE: Macro to name project

(OP)
but the macro still doesn't write the next input to the next row, any trick to do so? by the way, anyway to make excel to recognise repeatative input and prompt warning message when input is repeated? I'm new in visual basic, so help anyone?

RE: Macro to name project

...still doesn't write the next input to the next row

Do you mean put the second answer into cell A2 rather than B1?

...recognise repeatative input
Do you mean compare the values in A1 and A2/B1?

Or do you mean maintain a "log" of sorts to keep appending new project info below existing info?

In short, yeah - VBA can do any of that kind of stuff. You need to define a bit more clearly what you're trying to do.

RE: Macro to name project

This updated macro will keep adding entries in the next available row in columns A and B. Change the constants to start the lists in cells other than A1 and B1.

Killswitch

Sub Macro1()
Const ProjectCol = "A"
Const ClientCol = "B"
Const FirstRow = 1

Dim answer1 As String, LastRow As Integer

'get the project name
Message1 = "Enter project title"
Title1 = "Project info"
answer1 = ""
Do
    answer1 = InputBox(Message1, Title1, answer1)
Loop Until Len(answer1)

' determine the row to write the data to
LastRow = FirstRow
If Not IsEmpty(Range(ProjectCol & LastRow)) Then
' if the first row has an entry
    If IsEmpty(Range(ProjectCol & LastRow + 1)) Then
' use next row if it's empty
        LastRow = 2
    Else
        LastRow = Range(ProjectCol & LastRow).End(xlDown).Rows.Row + 1
        ' find the next empty row in column A
    End If
End If

' write the Project Name in column A
Range(ProjectCol & LastRow) = answer1

' get the client name
Message1 = "Enter client's name"
Title1 = "Client info"
answer1 = ""

Do
    answer1 = InputBox(Message1, Title1, answer1)
Loop Until Len(answer1)

' write the Client Name in column B and the same row as the Project
Range(ClientCol & LastRow) = answer1

End Sub

RE: Macro to name project

Sorry,

    If IsEmpty(Range(ProjectCol & LastRow + 1)) Then
    ' use next row if it's empty
        LastRow = 2


should be:

    If IsEmpty(Range(ProjectCol & LastRow + 1)) Then
    ' use next row if it's empty
        LastRow = LastRow + 1


Killswitch

RE: Macro to name project

(OP)
Fabulous!! I think that solved my question & improved my knowledge in VB, thanks killswitch...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close