Copy one column to another

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, I have the following VBA that copies from B to O. It works great, but I would like it to work automatically as soon as data is place in Column B. I don't need a button for it. Also should I put it in a Module or on the worksheet "Sheet1" (Xman)"? Thank you,

VBA Code:
Sub Copy()
Range("B3:B" & Cells(Rows.Count, "B").End(xlUp).Row).Copy Destination:=Range("O3")
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
copy to worksheet code module for sheet where copy is needed.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
Application.DisplayAlerts = False
    If Not Intersect(Columns(2), Target) Is Nothing Then
        Range("B3", ActiveSheet.Cells(Rows.Count, 2).End(xlup)).Copy Range("Q3")
    End If
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
 
Upvote 0
copy to worksheet code module for sheet where copy is needed.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
Application.DisplayAlerts = False
    If Not Intersect(Columns(2), Target) Is Nothing Then
        Range("B3", ActiveSheet.Cells(Rows.Count, 2).End(xlup)).Copy Range("Q3")
    End If
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Thank you, that is very good. I do have Conditional Formatting in both Columns C and O. It looks like its copy the Conditional Formatting over too. The code I have for Column C is:
Excel Formula:
=OR(AND(B3="D",OR(LEFT(C3)<>"1",ISERROR(-C3),LEN(C3)<>10)),AND(B3="P",OR(LEN(C3)=0,LEN(C3)>12)))
The Conditional Formatting I have for Column O is:
Excel Formula:
=OR(AND(N3="M",OR(LEFT(O3)<>"1",ISERROR(-O3),LEN(O3)<>10)),AND(N3="P",OR(LEN(O3)=0,LEN(O3)>12)))
The end result the I have a "D" where a "M" should be. Is there anywhere I can copy and paste VBA without the Conditional Format? I do apologize I didn't realize it would also copy the formatting.
 
Upvote 0
Replace the first code with this one. It will not carry the conditional formatting over to the new column.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
Application.DisplayAlerts = False
    If Not Intersect(Columns(2), Target) Is Nothing Then
        Range("B3", ActiveSheet.Cells(Rows.Count, 2).End(xlup)).Copy 
        Range("O3").PasteSpecial xlPasteValuesAndNumberFormats
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
 
Upvote 0
Replace the first code with this one. It will not carry the conditional formatting over to the new column.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
Application.DisplayAlerts = False
    If Not Intersect(Columns(2), Target) Is Nothing Then
        Range("B3", ActiveSheet.Cells(Rows.Count, 2).End(xlup)).Copy
        Range("O3").PasteSpecial xlPasteValuesAndNumberFormats
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
That works great, I do notice it leaves the green hatch boarder around the column to be copied and it is shaded where the items were pasted. I can select Escape and clear that. Is there one little line I can include like a select? Thank you, It safeguarded my formatting which was my biggest concern.
 
Upvote 0
Add the line in red font.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
Application.DisplayAlerts = False
    If Not Intersect(Columns(2), Target) Is Nothing Then
        Range("B3", ActiveSheet.Cells(Rows.Count, 2).End(xlup)).Copy 
        Range("O3").PasteSpecial xlPasteValuesAndNumberFormats
        Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
 
Upvote 0
Solution
Add the line in red font.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
Application.DisplayAlerts = False
    If Not Intersect(Columns(2), Target) Is Nothing Then
        Range("B3", ActiveSheet.Cells(Rows.Count, 2).End(xlup)).Copy
        Range("O3").PasteSpecial xlPasteValuesAndNumberFormats
        Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
I don't think I have anymore questions. Thank you for your unwavering support. You're great!
 
Upvote 0

Forum statistics

Threads
1,215,014
Messages
6,122,697
Members
449,092
Latest member
snoom82

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