+ Reply to Thread
Results 1 to 6 of 6

proper syntax

  1. #1
    Registered User
    Join Date
    12-05-2012
    Location
    victoria
    MS-Off Ver
    Excel 2010
    Posts
    55

    proper syntax

    hey,

    I want to enter both a string and a value into a cell but am unsure about the syntax.

    I want to enter "Project a" where "a" is an integer that counts up from 1 so I would get "Project 1", "Project 2".....

    thanks

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,791

    Re: proper syntax

    You could apply a Custom Format to the cells of:

    "Project "0

    and then put 1, 2, 3 etc in successive cells, or if you want a formula to copy down:

    =MAX(A$1:A1)+1

    in cell A2 and then copy that down.

    Hope this helps.

    Pete

  3. #3
    Registered User
    Join Date
    12-05-2012
    Location
    victoria
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: proper syntax

    yea that works but I am wanting to do it within VBA so that it inputs the new project name everytime I do a loop. I have it all working except the part of adding the number to the string.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Can you post the code you have?
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    12-05-2012
    Location
    victoria
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: proper syntax

    [Private Sub CommandButton3_Click()
    Sheets("Sheet1").Select
    Range("A3").Select
    Dim x, a, n, t As Integer

    x = 0
    a = 0
    n = 2
    Do Until Selection.Value = ""
    Selection.Offset(1, 0).Select
    x = x + 1
    a = a + 1
    Loop
    Selection.Offset(5, 1).Value = Selection.Offset(2, 0).Value
    x = x + 6
    Selection.Offset(-a, n).Select
    Do Until Selection.Value = ""
    a = 0
    Do Until Selection.Value = ""
    Selection.Offset(1, 0).Select
    a = a + 1
    Loop
    t=t+1
    Selection.Offset((x - a), -n).Value = "Project" & "t"
    Selection.Offset((x - a), (-n + 1)).Value = Selection.Offset(2, 0)
    x = x + 1
    Selection.Offset(-a, 2).Select
    n = n + 2
    Loop

    End Sub]

    the problem is the 7th to last line.. I dont know the proper syntax to make the t turn into its value.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Remove the quotes around t.

    Oh, and please use code tags.

+ 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