Re: Can A Macro "Add" Content To A Cell Without Replacing The Original Content?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Frank Kabel (frank.kabel_at_freenet.de)
Date: 03/24/04


Date: Thu, 25 Mar 2004 00:44:32 +0100

Hi
try
Sub paste_area()
Dim lastrow As Long
Dim row_index As Long
Dim col_index as integer
Dim text_value

text_value = "(512)"

for col_index = 12 to 16
lastrow = Active***.Cells(Rows.Count, col_index).End(xlUp).Row
For row_index = 1 To lastrow
    If Cells(row_index, col_index).Value <> "" Then
        Cells(row_index, col_index).Value = text_value & _
            Cells(row_index, col_index).Value
    End If
Next
next
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany
Minitman wrote:
> Hey Frank,
>
> It almost worked.
>
> I think I forgot to mention that these phone numbers are located in
> columns L, M. N, O and P.
>
> This code did all of column A!  (good thing I hadn't saved it yet)
<G>
>
> I tried to make a named range for columns L, M, N, O and P which I
> called "Phone".  I then exchange "A" with "Phone" but I got a type
> mismatch error.
>
> Any suggestions?
>
> TIA
>
> -Minitman
>
>
>
>
> On Wed, 24 Mar 2004 23:57:45 +0100, "Frank Kabel"
> <frank.kabel@freenet.de> wrote:
>
>> Sub paste_area()
>> Dim lastrow As Long
>> Dim row_index As Long
>> Dim text_value
>>
>> text_value = "(512)"
>>
>> lastrow = Active***.Cells(Rows.Count, "A").End(xlUp).Row
>> For row_index = 1 To lastrow
>>    If Cells(row_index, "A").Value <> "" Then
>>        Cells(row_index, "A").Value = text_value & _
>>            Cells(row_index, "A").Value
>>    End If
>> Next
>> End Sub

Quantcast