View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Request for VB to do something simple (insert text in a column of

Hi David:

Withour VBA, in B2 enter:
="XYZ" & A2 and copy down (assumes A1 is a header cell)

With VBA, YOU select a part of ANY column and run:

Sub david1()
For Each r In Selection
r.Offset(0, 1).Value = "XYZ" & r.Value
Next
End Sub

david1 will fill the adjact cells


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

david2 does not require you to Select the cells. It works on column A and
figures how far down to go.
--
Gary''s Student - gsnu2007a


"David Nebenzahl" wrote:

I'm having a terrible time with methods, objects, properties, ranges ...
all making my head sorta spin.

What I want to do is pretty simple: turn the first column of cells into
the second one:

ceo -- XYZceo
abc -- XYZabc
123 -- XYZ123
vba -- XYZvba

and so on.

I know it might involve Insert("XYZ"), and I want it to be generalized
and operate on all the cells in a given column, so it would probably use
CurrentRegion.Cells, but I'm stumped.

(An extra twist is that the sheet would have a header row, so the text
should only be inserted starting with the 2nd row.)

Any light that could be shed on this would be much appreciated.