A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

macro-add text



 
 
Thread Tools Display Modes
  #1  
Old May 1st, 2009, 12:32 PM posted to microsoft.public.excel.misc
puiuluipui
external usenet poster
 
Posts: 467
Default macro-add text

Hi, i need to add some text to some cells, but i need a macro linked to a
button to do this. If i select a cell and than i click the macro button, then
"(anul)" to appear in that cell, at the end of the text.

ex:-without button
a
John C
John C (ed)


Ex:-with button
a
John C (anul)
John C (ed) (anul)


Can this be done?
Thanks!
  #2  
Old May 1st, 2009, 12:37 PM posted to microsoft.public.excel.misc
Jacob Skaria
external usenet poster
 
Posts: 5,952
Default macro-add text

try selecting a cell and running the below macro

Sub Macro AddText()
Cells(activecell.Row,activecell.Column)= Activecell.Text & " (anul)"
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"puiuluipui" wrote:

Hi, i need to add some text to some cells, but i need a macro linked to a
button to do this. If i select a cell and than i click the macro button, then
"(anul)" to appear in that cell, at the end of the text.

ex:-without button
a
John C
John C (ed)


Ex:-with button
a
John C (anul)
John C (ed) (anul)


Can this be done?
Thanks!

  #3  
Old May 1st, 2009, 12:40 PM posted to microsoft.public.excel.misc
Dave Peterson
external usenet poster
 
Posts: 19,791
Default macro-add text

Option Explicit
Sub testme()

Dim myRng As Range
Dim myCell As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Please select a range with text values"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
.Value = .Value & " (anul)"
End With
Next myCell

End Sub


puiuluipui wrote:

Hi, i need to add some text to some cells, but i need a macro linked to a
button to do this. If i select a cell and than i click the macro button, then
"(anul)" to appear in that cell, at the end of the text.

ex:-without button
a
John C
John C (ed)

Ex:-with button
a
John C (anul)
John C (ed) (anul)

Can this be done?
Thanks!


--

Dave Peterson
  #4  
Old May 1st, 2009, 12:53 PM posted to microsoft.public.excel.misc
puiuluipui
external usenet poster
 
Posts: 467
Default macro-add text

It's working! But i forgot to say that i need "(anul)" to be red. Can the
text that i need to appear "(anul)", be red?
Thanks allot!

"Dave Peterson" a scris:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myCell As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Please select a range with text values"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
.Value = .Value & " (anul)"
End With
Next myCell

End Sub


puiuluipui wrote:

Hi, i need to add some text to some cells, but i need a macro linked to a
button to do this. If i select a cell and than i click the macro button, then
"(anul)" to appear in that cell, at the end of the text.

ex:-without button
a
John C
John C (ed)

Ex:-with button
a
John C (anul)
John C (ed) (anul)

Can this be done?
Thanks!


--

Dave Peterson

  #5  
Old May 1st, 2009, 01:10 PM posted to microsoft.public.excel.misc
Jacob Skaria
external usenet poster
 
Posts: 5,952
Default macro-add text

Please try this

Sub AddText()
Dim intTemp
Dim strAddtext As String
strAddtext = " (anul)"
For Each c In Selection
Cells(c.Row, c.Column) = Cells(c.Row, c.Column).Text & strAddtext
Cells(c.Row, c.Column).Characters(Start:=Len(Cells(c.Row, c.Column)) - _
Len(strAddtext) + 1, Length:=Len(strAddtext)).Font.Color = vbRed
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"puiuluipui" wrote:

It's working! But i forgot to say that i need "(anul)" to be red. Can the
text that i need to appear "(anul)", be red?
Thanks allot!

"Dave Peterson" a scris:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myCell As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Please select a range with text values"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
.Value = .Value & " (anul)"
End With
Next myCell

End Sub


puiuluipui wrote:

Hi, i need to add some text to some cells, but i need a macro linked to a
button to do this. If i select a cell and than i click the macro button, then
"(anul)" to appear in that cell, at the end of the text.

ex:-without button
a
John C
John C (ed)

Ex:-with button
a
John C (anul)
John C (ed) (anul)

Can this be done?
Thanks!


--

Dave Peterson

  #6  
Old May 1st, 2009, 01:25 PM posted to microsoft.public.excel.misc
puiuluipui
external usenet poster
 
Posts: 467
Default macro-add text

It's working great! Thanks allot!
Have a nice day!

"Jacob Skaria" a scris:

Please try this

Sub AddText()
Dim intTemp
Dim strAddtext As String
strAddtext = " (anul)"
For Each c In Selection
Cells(c.Row, c.Column) = Cells(c.Row, c.Column).Text & strAddtext
Cells(c.Row, c.Column).Characters(Start:=Len(Cells(c.Row, c.Column)) - _
Len(strAddtext) + 1, Length:=Len(strAddtext)).Font.Color = vbRed
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"puiuluipui" wrote:

It's working! But i forgot to say that i need "(anul)" to be red. Can the
text that i need to appear "(anul)", be red?
Thanks allot!

"Dave Peterson" a scris:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myCell As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Please select a range with text values"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
.Value = .Value & " (anul)"
End With
Next myCell

End Sub


puiuluipui wrote:

Hi, i need to add some text to some cells, but i need a macro linked to a
button to do this. If i select a cell and than i click the macro button, then
"(anul)" to appear in that cell, at the end of the text.

ex:-without button
a
John C
John C (ed)

Ex:-with button
a
John C (anul)
John C (ed) (anul)

Can this be done?
Thanks!

--

Dave Peterson

  #7  
Old May 1st, 2009, 03:03 PM posted to microsoft.public.excel.misc
Dave Peterson
external usenet poster
 
Posts: 19,791
Default macro-add text

I would still limit my changes to cells in the selection that are not formulas
and non-numeric:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myCell As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Please select a range with text values"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
.Value = .Value & " (anul)"
.Characters(Start:=Len(.Value) - 5, Length:=6).Font.ColorIndex = 3
End With
Next myCell

End Sub

puiuluipui wrote:

It's working! But i forgot to say that i need "(anul)" to be red. Can the
text that i need to appear "(anul)", be red?
Thanks allot!

"Dave Peterson" a scris:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myCell As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Please select a range with text values"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
.Value = .Value & " (anul)"
End With
Next myCell

End Sub


puiuluipui wrote:

Hi, i need to add some text to some cells, but i need a macro linked to a
button to do this. If i select a cell and than i click the macro button, then
"(anul)" to appear in that cell, at the end of the text.

ex:-without button
a
John C
John C (ed)

Ex:-with button
a
John C (anul)
John C (ed) (anul)

Can this be done?
Thanks!


--

Dave Peterson


--

Dave Peterson
  #8  
Old May 14th, 2009, 08:59 PM posted to microsoft.public.excel.misc
puiuluipui
external usenet poster
 
Posts: 467
Default macro-add text

Hi, it's working great!
Thanks allot!


"Dave Peterson" wrote:

I would still limit my changes to cells in the selection that are not formulas
and non-numeric:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myCell As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Please select a range with text values"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
.Value = .Value & " (anul)"
.Characters(Start:=Len(.Value) - 5, Length:=6).Font.ColorIndex = 3
End With
Next myCell

End Sub

puiuluipui wrote:

It's working! But i forgot to say that i need "(anul)" to be red. Can the
text that i need to appear "(anul)", be red?
Thanks allot!

"Dave Peterson" a scris:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myCell As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Please select a range with text values"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
.Value = .Value & " (anul)"
End With
Next myCell

End Sub


puiuluipui wrote:

Hi, i need to add some text to some cells, but i need a macro linked to a
button to do this. If i select a cell and than i click the macro button, then
"(anul)" to appear in that cell, at the end of the text.

ex:-without button
a
John C
John C (ed)

Ex:-with button
a
John C (anul)
John C (ed) (anul)

Can this be done?
Thanks!

--

Dave Peterson


--

Dave Peterson

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:44 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.