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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

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