Macro to Copy Specific Columns from One Worksheet to Another in Excel (6 Methods)

Method 1 – Copy selected Columns from One Worksheet to Another Using Macro

The sample dataset contains some information about the employees of a company. We will use VBA code to copy Columns B & D here.

Copy Certain Columns from One Worksheet to Another Worksheet Using Macro

 

STEPS:

  • Go to the Developer tab and select Visual Basic.

Copy Certain Columns from One Worksheet to Another Worksheet Using Macro

  • The Visual Basic window will open.
  • Go to Insert and select Module.
  • Enter the below code in the Module window.
Sub Copy_Specific_Columns_ToAnother_Sheet()
Sheets("Copy Specific Columns").Range("B:B").Copy Sheets("Copied Columns").Range("A:A")
Sheets("Copy Specific Columns").Range("D:D").Copy Sheets("Copied Columns").Range("B:B")
End Sub

Copy Certain Columns from One Worksheet to Another Worksheet Using Macro

Here, we have declared the Sub procedure as ‘Copy_Specific_Columns_ToAnother_Sheet’. We selected the sheet from which we want to copy the columns inside Sheets(“”)  and also selected the columns using the range. Then, we select the sheet where we wanted to copy the columns. We applied this code for Column B & Column D and copied them to Column A & Column B of another sheet.

  • Press Ctrl + S or click the Save icon to save the code.
  • Go to Macros in the Developer tab.

Copy Certain Columns from One Worksheet to Another Worksheet Using Macro

  • Select Run from the Macro window.

Copy Certain Columns from One Worksheet to Another Worksheet Using Macro

  • You can also run any code after saving it by pressing the F5 key.
  • The results are returned as below.

Copy Certain Columns from One Worksheet to Another Worksheet Using Macro

Read More: How to Use Excel VBA to Copy Range to Another Excel Sheet


Method 2 – Copy Columns to Another Sheet with Formatting

 

STEPS:

  • Go to the Developer tab and select Visual Basic. 

Macro to Copy Particular Columns to Another Sheet with Format

  • Go to Insert and select Module.
  • Enter the below code in the Module window.
Sub Copy_Specific_Columns_with_Format()
Sheets("Copy Specific Columns").Range("B:B").Copy Sheets("Copied Columns").Range("B:B")
Sheets("Copy Specific Columns").Range("D:D").Copy Sheets("Copied Columns").Range("D:D")
End Sub

Macro to Copy Particular Columns to Another Sheet with Format

This code  copies Column B of the Copy Specific Columns sheet to Column B of Copied Columns sheet. If you want to copy more columns repeat the same command, changing the column in the range, which we have done for Column D here.

  • Press Ctrl + S or click the Save icon to save the code.
  • Go to Macros in the Developer tab.

Macro to Copy Particular Columns to Another Sheet with Format

  • Select Run from the Macro.

Macro to Copy Particular Columns to Another Sheet with Format

 

  • The results are returned as below.

Macro to Copy Particular Columns to Another Sheet with Format

Read More: Excel VBA to Copy Rows to Another Worksheet Based on Criteria


Method 3 – Copy Columns from One Sheet to Another without Formatting

 

STEPS:

  • Go to the Developer tab and select Visual Basic.

Copy Definite Columns from One Sheet to Another without Format

  • Go to Insert and select Module.
  • Enter the VBA code in the Module window.
Sub Copy_Columns_WithoutFormat()
Range("B:B").Copy
Sheets("Copied Without Format").Range("A1").PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D:D").Copy
Sheets("Copied Without Format").Range("B1").PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

Copy Definite Columns from One Sheet to Another without Format

Here, we have used the same method to copy the columns but we have used the Paste:=xlPasteValues to only paste values.

  • Press Ctrl + S or click the Save icon to save the code.
  • Select Macros from the Developer tab.

Copy Definite Columns from One Sheet to Another without Format

  • Click Run from the Macro window.

Copy Definite Columns from One Sheet to Another without Format

  • The results are returned as below.

Copy Definite Columns from One Sheet to Another without Format

Read More: Excel VBA: Copy Range to Another Workbook


Method 4 – Copy Column to a New Sheet with Formula

In this example, we have added the SUM function in our dataset to calculate the total salary. If the previous methods are used the Macro will only copy the values.

Excel VBA Copy Column to a New Sheet with Formula

 

STEPS:

  • Go to the Developer tab and select Visual Basic. A Visual Basic window will appear.

Excel VBA Copy Column to a New Sheet with Formula

  • Go to Insert and select Module.
  • Enter the code in the Module window.
Sub Copy_Column_with_Formula()
Range("F:F").Copy
Sheets("Copied With Formula").Range("B1").PasteSpecial Paste:=xlPasteFormulas, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub

Excel VBA Copy Column to a New Sheet with Formula

The code uses Paste:=xlPasteFormulas instead of Paste:=xlPaste Values to paste with formula. We used only one column here, but to apply it to other columns, copy the code and paste it, changing the column in the range.

  • Press Ctrl + S to save the code.
  • Go to the Developer tab and select Macros.

Excel VBA Copy Column to a New Sheet with Formula

  • Run the code from the Macro dialog box.

Excel VBA Copy Column to a New Sheet with Formula

  • You will see the column containing the formula in another worksheet.

Excel VBA Copy Column to a New Sheet with Formula

 


Method 5 – Copy Specific Columns to Another Sheet with AutoFit

 

STEPS:

  • Go to the Developer tab and select Visual Basic.
  • A Visual Basic window will appear.

  • Go to Insert and select Module.
  • Enter the code in the Module window.
Sub Copy_Columns_with_AutoFit()
Sheets("With AutoFit").Select
Range("B:B").Copy
Sheets("Copied With AutoFit").Select
Range("B1").Select
Sheets("With AutoFit").Select
Range("D:D").Copy
Sheets("Copied With AutoFit").Select
Range("C1").Select
ActiveSheet.Paste
Columns("B:F").AutoFit
End Sub

We have used the copy and paste method here and the AutoFit command at the end.

  • Click the Save icon or press Ctrl + S to save the code.
  • Select Macros from the Developer tab.

  • Select the desired code from the Macro window and click Run it.

  • The results are returned as below.

Read More: Macro to Copy and Paste from One Worksheet to Another


Method 6 – Copy Specific Columns Keeping Same Column Width

 

STEPS:

  • Go to the Developer tab and select Visual Basic to the Visual Basic window.

  • Go to Insert and select Module.
  • Enter the below code in the Module window.
Sub Copy_Columns_with_ColumnWidth()
Range("B:B").Copy Destination:=Sheets("Copied With ColumnWidth").Range("B1")
Range("B:B").Copy
Sheets("Copied With ColumnWidth").Range("B1").PasteSpecial Paste:=xlPasteColumnWidths, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("F:F").Copy Destination:=Sheets("Copied With ColumnWidth").Range("F1")
Range("F:F").Copy
Sheets("Copied With ColumnWidth").Range("F1").PasteSpecial Paste:=xlPasteColumnWidths, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub

Here, we have copied Column B and Column F. We have used Paste:=xlPasteColumnWidths to keep the column width the same.

  • Go to the Developer tab on the ribbon and select Macros.

  • Select the code from the Macro window and Run it.

  • The results are returned as below.


Download Practice Book

Download the practice book here.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Mursalin Ibne Salehin
Mursalin Ibne Salehin

Mursalin Ibne Salehin holds a BSc in Electrical and Electronics Engineering from Bangladesh University of Engineering and Technology. Over the past 2 years, he has actively contributed to the ExcelDemy project, where he authored over 150 articles. He has also led a team with content development works. Currently, he is working as a Reviewer in the ExcelDemy Project. He likes using and learning about Microsoft Office, especially Excel. He is interested in data analysis with Excel, machine learning,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo