Discussion:
Adding a "1" in front of everything in column A
(too old to reply)
alexm999
2005-12-02 21:53:03 UTC
Permalink
I'd like to add a "1" (number one) in front of everything in column A.
can use =1&A1 but it's too tedius to do to every record in ever
spreadsheet.

I tried creating a macro, but for blank rows say A1 to A100 hav
numbers, but after that it adds a 1 in an empty cell.

Is there anyone who can help me with this

--
alexm99
-----------------------------------------------------------------------
alexm999's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=491
View this thread: http://www.excelforum.com/showthread.php?threadid=49031
Gary Keramidas
2005-12-02 22:14:49 UTC
Permalink
try this, i am assuming the string you want is text so it didn't sum if
there were existing numbers:

Option Explicit
Dim lastrow As Long
Dim cell As Range
Sub test()
lastrow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In Range("A1:A" & lastrow)
cell.Value = "1" & cell.Value
Next

End Sub
--
Gary
I'd like to add a "1" (number one) in front of everything in column A. I
can use =1&A1 but it's too tedius to do to every record in every
spreadsheet.
I tried creating a macro, but for blank rows say A1 to A100 have
numbers, but after that it adds a 1 in an empty cell.
Is there anyone who can help me with this?
--
alexm999
------------------------------------------------------------------------
http://www.excelforum.com/member.php?action=getinfo&userid=4918
View this thread: http://www.excelforum.com/showthread.php?threadid=490316
Ken Johnson
2005-12-02 22:27:19 UTC
Permalink
Hi Alex,
If you don't want to use a macro you could try filling this formula
down a spare column starting in row 2 (You probably have a heading in
row 1)

=IF(A2<>"","1" & A2,"")

This avoids the problem you are having with blank cells.

Ken Johnson
Myles
2005-12-03 06:57:16 UTC
Permalink
Or,

Sub AddOne()

For each c in Range("a:a")
If Not Isempty(c) Then
c.value = 1 & c.value
End if
Next

End Sub
--
Myles
------------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=28746
View this thread: http://www.excelforum.com/showthread.php?threadid=490316
Loading...