modify vba code to copy only values not formulas

zoism

New Member
Joined
Jan 12, 2015
Messages
2
i have the following vba code to copy values from the column A to the next column,but it copy the formulas,i want only the values to be copied, so that when i clear the cell in A not to be cleared in B.

<code>
Code:
</code><code>Private Sub Worksheet_Change(ByVal Target As Range)
    Dim A As Range, intr As Range, r As Range
    Set A = Range("A:A")
    Set intr = Intersect(A, Target)
    If intr Is Nothing Then Exit Sub

    Application.EnableEvents = False
        For Each r In intr
            If r.Value <> "" Then
                r.Copy r.Offset(0, 1)
            End If
        Next r
    Application.EnableEvents = True
End Sub
</code>
<code></code>
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Change this line
Code:
<code>r.Copy r.Offset(0, 1)</code>
to
Code:
r.Offset(0, 1).Value = r.Value
 
Upvote 0
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">After Stepping through this code line >>>: Set intr = Intersect(A, Target) What is the Address of your Range "intr"? Also, on your change event how many cells end up being the target of your change?</code>
 
Upvote 0

Forum statistics

Threads
1,217,376
Messages
6,136,198
Members
449,998
Latest member
jpaul123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top