Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>regarding copy of multiple columns, it is possible (eg <code>Range("A2:A4,B2:B4,D2:D4,F2:F4").Copy</code> ), but when you paste them they will be in a continuous range - better to just copy separately</p> <p>I've re-factored your code give you some hints</p> <pre><code>Sub Convert_to_Digi() ' First delete existing data Dim SrcWkb As Workbook Dim csvWkb As Workbook Dim srcSheet As Worksheet Dim StartRow As Long Dim wkbname As Variant Dim xlsFiles As Variant Dim MyRange As Range Dim NewName As Variant Dim csvName As String StartRow = 2 ' Get the workbooks to open xlsFiles = Application.GetOpenFilename(FileFilter:="Excel files (*.xls), *.xls", MultiSelect:=True) If VarType(xlsFiles) = vbBoolean Then Exit Sub ' Loop through each workbook and copy the data to this CSV For Each wkbname In xlsFiles Set SrcWkb = Workbooks.Open(Filename:=wkbname, ReadOnly:=False) Set srcSheet = SrcWkb.Worksheets("export_label_conf") ' Get used range on sheet Set MyRange = srcSheet.UsedRange ' Adjust to exclude top row Set MyRange = MyRange.Offset(1, 0).Resize(MyRange.Rows.Count - 1) NewName = srcSheet.Cells(3, 2) &amp; ".csv" If MyRange.Row + MyRange.Rows.Count - 1 &gt;= StartRow Then Set csvWkb = Workbooks.Open(Filename:="C:\DIGITAL\template.csv", ReadOnly:=False) ' copy column A MyRange.Columns(1).Copy ' paste into CSV template file, column K csvWkb.ActiveSheet.Cells(2, 11).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ' copy column B MyRange.Columns(4).Copy ' paste into CSV template file csvWkb.ActiveSheet.Cells(2, 5).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ' copy column D MyRange.Columns(4).Copy ' paste into CSV template file, column A csvWkb.ActiveSheet.Cells(2, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ' copy column F MyRange.Columns(6).Copy ' paste into CSV template file, column AD csvWkb.ActiveSheet.Cells(2, 30).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ' and save template as new CSV with barcode as name csvName = CurDir &amp; "\" &amp; NewName ' using CurDir is a bit dangerous: how do you know what its set to? ActiveWorkbook.SaveAs Filename:=csvName, FileFormat:=xlCSV, CreateBackup:=False End If SrcWkb.Close Next wkbname End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload