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
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
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
RE: Macro to name project
RE: Macro to name project
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
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
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