Consulting

Results 1 to 8 of 8

Thread: Excel Add Text in Cell with already existing text

  1. #1

    Excel Add Text in Cell with already existing text

    Hi All

    I want to have a button/function, which, when clicked, will add a certain text to the already existing text in that cell. this is what i have:
    [VBA]Sub EngagementsMCS_Button1_Click()

    ActiveCell = "" & ("On HOLD!")


    End Sub[/VBA]

    but it deletes the existing text in the cell unfortunately....

    any help?

    regards

    grohm

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub EngagementsMCS_Button1_Click()

    With ActiveCell

    .Value = .Value & "On HOLD!"
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    [vba]

    Sub EngagementsMCS_Button1_Click()

    With ActiveCell

    .Value = .Value & "On HOLD!"
    End With

    End Sub
    [/vba]
    hmmm, still doesn't work. same outcome as above :-(

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Nonsense, if the activecell has a value, this appends to it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Quote Originally Posted by xld
    Nonsense, if the activecell has a value, this appends to it.
    ah yes, you were right. sorry for that. is there a opposite to & ?

    i mean, i want to delete that same value from the cell that i added, so i could completely reverse the process from the first button. possible?

    many thx!

  6. #6
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    266
    Location
    you mean if the value is "blabla on hold" you want a button to make it "blabla"?

    i think you would have to split the cellvalue and check each part.

    [vba]
    txt = ActiveCell.Value
    x = Split(txt, " ")
    j = 0

    For i = 0 To UBound(x)
    If x(i) = "On" And x(i + 1) = "HOLD" Then
    while j < i
    ActiveCell.Value = ActiveCell.Value & " " & x(j)
    j = j + 1
    Wend
    End If
    Next i

    [/vba]

    think this should work
    Last edited by Ago; 02-21-2008 at 04:23 AM.

  7. #7
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    266
    Location
    wait!
    i just noticed it will add a space in the begining of each cell and osme other problems :-)
    this should delete the problem with the space.

    [vba]
    Sub test()
    txt = ActiveCell.Value
    x = Split(txt, " ")
    j = 0

    For i = 0 To UBound(x)
    If x(i) = "On" And x(i + 1) = "HOLD" Then
    ActiveCell.Value = ""
    While j < i
    If j = 0 Then
    ActiveCell.Value = x(j)
    Else
    ActiveCell.Value = ActiveCell.Value & " " & x(j)
    End If
    j = j + 1

    Wend
    i = UBound(x)
    End If
    Next i
    End Sub




    [/vba]
    Last edited by Ago; 02-21-2008 at 04:36 AM.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With ActiveCell

    .Value = Replace(.Value, "On Hold", "")
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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