+ Reply to Thread
Results 1 to 7 of 7

Concatenate & format standard text in cell A1, Sheet1 with strings from two input boxes

  1. #1
    Registered User
    Join Date
    12-02-2012
    Location
    Silver Bay, MN
    MS-Off Ver
    Excel 2010
    Posts
    47

    Concatenate & format standard text in cell A1, Sheet1 with strings from two input boxes

    I am stumped on how to create a header in A1, Sheet1 which combines the following text NLCAB BUDGET SUMMARY: followed by strProgramName - strProgramYear with strings derived from two input boxes coded in a standard module.

    Public Sub btnEnterInfoIntoWorkbook()

    Dim strProgramName As String
    Dim strProgramYear As String

    'Get the user's first and last name.

    strProgramName = InputBox(Prompt:="Type the name of the program here. (Please use Title Case.)", Title:="ENTER NEW WORKBOOK INFORMATION")
    strProgramYear = InputBox(Prompt:="Type the program's budget year here. (yyyy)", Title:="ENTER NEW WORKBOOK INFORMATION")

    'Proceed only if both input boxes have text in them.
    If strProgramName = "" Or strProgramYear = "" Then
    MsgBox Prompt:="You did not enter all required information. You may edit as needed in the first row of the Budget Summary sheet."

    Else

    MsgBox Prompt:="You entered: " & strProgramName & " - " & strProgramYear & ". If this is not correct, you may edit in the first row of the Budget Summary sheet.", Title:="ENTER NEW WORKBOOK INFORMATION"

    End If
    End Sub

    This code module does the following:[INDENT]1.) When file is opened, an input box asks for program name - (strProgramName),[INDENT]2.) Followed by a second input box asking for program year - (strProgramYear),[INDENT]3.) There is then a test to determine if both boxes return a value. If so, the sub ends,[INDENT]4.) If one or both input boxes have no information, there is another message and the sub ends.[INDENT]5.) In 3 and 4 above, the user is informed if there is incorrect or missing data and that data may be edited directly in cell A1, Sheet1.

    The header should look like this:

    NCCAB BUDGET SUMMARY: Program Name - Year

    Formating as follows:

    Ariel, 20pt, Bold; Caps as shown; Double spaces after colon, Name and hyphen; Program Name should be in case title format

    Thank you very much for your assistance. :=)
    Last edited by mandora; 12-27-2012 at 04:42 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Concatenate & format standard text in cell A1, Sheet1 with strings from two input boxe

    attach a sample file with code and desired result
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    12-21-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Concatenate & format standard text in cell A1, Sheet1 with strings from two input boxe

    Try this: I assume that Budget Summary is "Sheet1", if not replace with correct sheet name.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-02-2012
    Location
    Silver Bay, MN
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Concatenate & format standard text in cell A1, Sheet1 with strings from two input boxe

    This is what I have so far but it does not include the NLCAB text. I am going to try Kiran.Sunkara's code as I can see it addresses all the conditions I am trying to incorporate. - mandora


    Sub EnterProgramNameAndYear()
    Dim y As String, x As String

    Do Until Len(y) > 0
    y = InputBox("Enter Program Name", "Enter Program Name using Title Case")
    If Len(y) = 0 Then MsgBox "You Must Enter Program Name", 16, "Message"
    Loop

    Do Until Len(x) > 0
    x = InputBox("Enter Program Year", "Enter Program Year as yyyy")
    If Len(x) = 0 Then MsgBox "You Must Enter Program Year", 16, "Message"
    Loop

    Range("A1") = y & " - " & x

    End Sub

  5. #5
    Registered User
    Join Date
    12-02-2012
    Location
    Silver Bay, MN
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Concatenate & format standard text in cell A1, Sheet1 with strings from two input boxe

    I adopted most of Kiran.Sunkara's code with minor changes in some prompts and message box header text for clarity. I added two vbOKOnly controls and dropped the suggested formating portion since this can be set directly on the sheet. If someone should want to edit the formating without going into vba, thats fine. I will happily give Kiran.Sunkara a positive rating!


    Public Sub btnEnterInfoIntoWorkbook()

    Dim strProgramName As String
    Dim strProgramYear As String

    'Get the program name and budget year.
    strProgramName = InputBox(Prompt:="Type the name of the program in Title Case.", Title:=" Enter Program Name in Title Case")
    strProgramYear = InputBox(Prompt:="Type the program's budget year as yyyy", Title:=" Enter Program's Budget Year as yyyy")

    'Proceed only if both input boxes have text in them.
    If strProgramName = "" Or strProgramYear = "" Then
    MsgBox "YOU DID NOT ENTER ALL REQUIRED INFORMATION." _
    & vbNewLine & vbNewLine & "Edit header in cell ""A1"" of the Budget Summary.", _
    vbInformation + vbOKOnly, " Confirmation of Budget Summary Header Information"
    Else
    MsgBox "You entered: " & strProgramName & " - " & strProgramYear & "" _
    & vbNewLine & vbNewLine & "Edit header, as needed, in cell ""A1"" of the Budget Summary.", _
    vbInformation + vbOKOnly, " Confirmation of Budget Summary Header Information"

    Sheet1.Range("A1") = "NCCAB BUDGET SUMMARY: " & WorksheetFunction.Proper(strProgramName) & " - " & strProgramYear

    ' Sheet1.Range("A1").Select
    ' With Selection.Font
    ' .Name = "Arial"
    ' .Size = 20
    ' .Strikethrough = False
    ' .Superscript = False
    ' .Subscript = False
    ' .OutlineFont = False
    ' .Shadow = False
    ' .Underline = xlUnderlineStyleNone
    ' .ColorIndex = 1
    ' End With
    ' Selection.Font.Bold = True

    End If
    End Sub

  6. #6
    Registered User
    Join Date
    12-02-2012
    Location
    Silver Bay, MN
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Concatenate & format standard text in cell A1, Sheet1 with strings from two input boxe

    Thanks for your willingness to help patel45. I did try Kiran.Sunkara's recommendation and it worked so well that problem is solved.

  7. #7
    Registered User
    Join Date
    12-21-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Concatenate & format standard text in cell A1, Sheet1 with strings from two input boxe

    Glad to know it had worked. Happy to support any thime!


    Mark your post [SOLVED] if it has been answered satisfactorily, by editing your original post using advanced mode.
    Thank those that provided useful help, its nice and its very well appreciated...use the star on the lower left of the post
    Hope this helps.
    Kiran

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1