VBA code to copy data from columns paste in new worksheet and save.

Addictions

Board Regular
Joined
May 27, 2018
Messages
60
Office Version
  1. 365
Hello,

Would like to ask if you possibly know VBA code to copy data from columns SKU, Title, Picture then paste it in new workbook and save it on desktop as a file name results?.

Thanks for help in advance.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You didn't give a whole lot to work with, but maybe you can use this.

Code:
Sub t()
Dim col1 As Range, col2 As Range, col3 As Range, wb As Workbook
With ActiveSheet
    Set col1 = .Rows(1).Find("SKU", , xlValues)
    Set col2 = .Rows(1).Find("Title", , xlValues)
    Set col3 = .Rows(1).Find("Picture", , xlValues)
End With
Set wb = Workbooks.Add
    If Not col1 Is Nothing Then
        col1.EntireColumn.Copy wb.Sheets(1).Range("A1")
    If Not col2 Is Nothing Then
        col2.EntireColumn.Copy wb.Sheets(1).Range("B1")
    If Not col3 Is Nothing Then
        col3.EntireColumn.Copy wb.Sheets(1).Range("C1")
    End If
    End If
    End If
wb.SaveAs "C:\Desktop\Results.xlsx"
wb.Close False
End Sub
 
Last edited:
Upvote 0
Hi,

I really appreciate your help. Thank you a lot!

If I change col1.EntireColumn.Copy to col1.EntireColumn.Delete would it delete the column?.
 
Upvote 0
You didn't give a whole lot to work with, but maybe you can use this.

Code:
Sub t()
Dim col1 As Range, col2 As Range, col3 As Range, wb As Workbook
With ActiveSheet
    Set col1 = .Rows(1).Find("SKU", , xlValues)
    Set col2 = .Rows(1).Find("Title", , xlValues)
    Set col3 = .Rows(1).Find("Picture", , xlValues)
End With
Set wb = Workbooks.Add
    If Not col1 Is Nothing Then
        col1.EntireColumn.Copy wb.Sheets(1).Range("A1")
    If Not col2 Is Nothing Then
        col2.EntireColumn.Copy wb.Sheets(1).Range("B1")
    If Not col3 Is Nothing Then
        col3.EntireColumn.Copy wb.Sheets(1).Range("C1")
    End If
    End If
    End If
wb.SaveAs "C:\Desktop\Results.xlsx"
wb.Close False
End Sub

What should I amend to paste results as values so it does not copy formula?.
Thanks in advance!
 
Upvote 0
Code:
Sub t()
Dim col1 As Range, col2 As Range, col3 As Range, wb As Workbook
With ActiveSheet
    Set col1 = .Rows(1).Find("SKU", , xlValues)
    Set col2 = .Rows(1).Find("Title", , xlValues)
    Set col3 = .Rows(1).Find("Picture", , xlValues)
End With
Set wb = Workbooks.Add
    If Not col1 Is Nothing Then
        col1.EntireColumn.Copy 
        wb.Sheets(1).Range("A1").PasteSpecial xlPasteValues
    If Not col2 Is Nothing Then
        col2.EntireColumn.Copy 
        wb.Sheets(1).Range("B1").PasteSpecial xlPasteValues
    If Not col3 Is Nothing Then
        col3.EntireColumn.Copy 
        wb.Sheets(1).Range("C1").PasteSpecial xlPasteValues
    End If
    End If
    End If
wb.SaveAs "C:\Desktop\Results.xlsx"
wb.Close False
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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