View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Request for VB to do something simple (insert text in a column of cells)

Sub Add_Text_Left()
Dim Cell As Range
Dim moretext As String
Dim thisrng As Range
On Error GoTo endit
Set thisrng = Range(ActiveCell.Address & "," & Selection.Address) _
.SpecialCells(xlCellTypeConstants, xlTextValues)
moretext = InputBox("Enter your Text")
For Each Cell In thisrng
Cell.Value = moretext & Cell.Value
Next
Exit Sub
endit:
MsgBox "only formulas in range"
End Sub

Select A2 then SHIFT + End + Downarrow.

The run the macro.


Gord Dibben MS Excel MVP

On Tue, 20 Nov 2007 09:18:45 -0800, David Nebenzahl
wrote:

On 11/20/2007 1:56 AM Gary''s Student spake thus:

With VBA, run david2:

Sub david2()
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To n
Cells(i, 2).Value = "XYZ" & Cells(i, 1).Value
Next
End Sub


Thanks for that. I changed it a little:

Sub Format4Upload
n = Cells(Rows.Count, "D").End(xlUp).Row
For i = 2 To n
Cells(i, 4).Characters(0, 0).Insert ("XYZ")
Next
End Sub

Works fine. But of course I need something mo how do I skip cells
that are blank? (In other words, don't insert anything if the cell is
blank).

Thanks again.