make shorter code

elmnas

Board Regular
Joined
Feb 20, 2015
Messages
206
Hello people,

I have made a very long code....
But I want to make it shorter, but I don't know how...
I got thoughts about create a kind of an array/case/for loop instead,
have someone a suggestion how to make this code shorter?

Code:
Sub GetColData()
'This function Get all the column data from the "Company" sheet.
' If name "xxx" then copy following sheets to current workbook.
For Each sht In ThisWorkbook.Worksheets
    mysheetname = sht.Name
    
        If sht.Name Like "Volvo_3P*" Then
        Sheets(mysheetname).Select
        Columns("A:A").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("A:A").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("C:C").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("D:D").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("D:D").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("H:H").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("G:G").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("J:J").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("H:H").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("K:K").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("I:I").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("L:L").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("J:J").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("M:M").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("E:E").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("F:F").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("M:M").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("U:U").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("O:O").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("AB:AB").Select
        ActiveSheet.Paste
        End If
        
        If sht.Name Like "Volvo_Penta*" Then
        Sheets(mysheetname).Select
        Columns("A:A").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("A:A").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("C:C").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("D:D").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("D:D").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("H:H").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("G:G").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("J:J").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("H:H").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("K:K").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("I:I").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("L:L").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("J:J").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("M:M").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("E:E").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("F:F").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("M:M").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("U:U").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("O:O").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("AB:AB").Select
        ActiveSheet.Paste
        End If
        
        If sht.Name Like "Volvo_Bus*" Then
        Sheets(mysheetname).Select
        Columns("A:A").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("A:A").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("C:C").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("D:D").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("D:D").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("H:H").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("G:G").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("J:J").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("H:H").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("K:K").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("I:I").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("L:L").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("J:J").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("M:M").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("E:E").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("F:F").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("M:M").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("U:U").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("O:O").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("AB:AB").Select
        ActiveSheet.Paste
        End If
        
        If sht.Name Like "Volvo_Business_Service*" Then
        Sheets(mysheetname).Select
        Columns("A:A").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("A:A").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("C:C").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("D:D").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("D:D").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("H:H").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("G:G").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("J:J").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("H:H").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("K:K").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("I:I").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("L:L").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("J:J").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("M:M").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("E:E").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("F:F").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("M:M").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("U:U").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("O:O").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("AB:AB").Select
        ActiveSheet.Paste
        End If
        
        If sht.Name Like "Volvo_Group_Trucks_Technology*" Then
        Sheets(mysheetname).Select
        Columns("A:A").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("A:A").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("C:C").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("D:D").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("D:D").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("H:H").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("G:G").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("J:J").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("H:H").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("K:K").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("I:I").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("L:L").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("J:J").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("M:M").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("E:E").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("F:F").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("M:M").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("U:U").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("O:O").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("AB:AB").Select
        ActiveSheet.Paste
        End If
        
        If sht.Name Like "Volvo_Information_Technology_AB*" Then
        Sheets(mysheetname).Select
        Columns("A:A").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("A:A").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("C:C").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("D:D").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("D:D").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("H:H").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("G:G").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("J:J").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("H:H").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("K:K").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("I:I").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("L:L").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("J:J").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("M:M").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("E:E").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("F:F").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("M:M").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("U:U").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("O:O").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("AB:AB").Select
        ActiveSheet.Paste
        End If
        
         If sht.Name Like "Volvo_Group_Sweden*" Then
        Sheets(mysheetname).Select
        Columns("A:A").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("A:A").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("C:C").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("D:D").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("D:D").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("H:H").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("G:G").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("J:J").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("H:H").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("K:K").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("I:I").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("L:L").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("J:J").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("M:M").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("E:E").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("F:F").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("M:M").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("U:U").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("O:O").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("AB:AB").Select
        ActiveSheet.Paste
        End If
        
        
        If sht.Name Like "Volvo_IT*" Then
        Sheets(mysheetname).Select
        Columns("A:A").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("A:A").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("C:C").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("D:D").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("D:D").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("H:H").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("E:E").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("I:I").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("G:G").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("J:J").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("H:H").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("K:K").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("I:I").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("L:L").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("J:J").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("M:M").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("E:E").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("K:K").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("F:F").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("M:M").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("U:U").Select
        ActiveSheet.Paste
        
        Sheets(mysheetname).Select
        Columns("O:O").Select
        Selection.Copy
        Sheets("Target_sheet").Select
        Columns("AB:AB").Select
        ActiveSheet.Paste
        End If


    Next sht
End Sub

Thank you in advance
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
There seems to be little relation between the source column and the destination column, this makes it almost impossible to append a loop. You could use names for your selections and order them in such a way that you address them with an integer in a loop, e.g. SourceColumn1 DestinationColumn1
Your code would become something like this:
Code:
for i = 1 to 20 ' or whatever number of columns you like to copy
Range("SourceColumn" & i).Copy
Range("DestinationColumn" & i).PasteSpecial
Next
 
Upvote 0
Hi

Something like this
Code:
Sub elmnas()
Dim InAry, OutAry
Dim Col, i
Dim mysheetname As String

InAry = Array(1, 3, 4, 5, 7)
OutAry = Array(1, 4, 8, 9, 10)

For Each sht In ThisWorkbook.Worksheets
    mysheetname = sht.Name
    
    If sht.Name Like "Volvo_3P*" Then
     For Col = 0 To UBound(InAry, 1)
     Sheets(mysheetname).Column(InAry(Col)).Copy Destination:=Sheets("Target_sheet").Column(OutAry(Col))
     Next Col
    End If
Next sht

End Sub

Specify the source columns in InAry and the destination Columns in OutAry.

You could also create a further array for the sheets you need to copy.

hth

Ps You do realise that some of the copies appear to be duplicated to the same destination columns!
 
Last edited:
Upvote 0
Hi

Something like this
Code:
Sub elmnas()
Dim InAry, OutAry
Dim Col, i
Dim mysheetname As String

InAry = Array(1, 3, 4, 5, 7)
OutAry = Array(1, 4, 8, 9, 10)

For Each sht In ThisWorkbook.Worksheets
    mysheetname = sht.Name
    
    If sht.Name Like "Volvo_3P*" Then
     For Col = 0 To UBound(InAry, 1)
     Sheets(mysheetname).Column(InAry(Col)).Copy Destination:=Sheets("Target_sheet").Column(OutAry(Col))
     Next Col
    End If
Next sht

End Sub

Specify the source columns in InAry and the destination Columns in OutAry.

You could also create a further array for the sheets you need to copy.

hth

Ps You do realise that some of the copies appear to be duplicated to the same destination columns!


I like the code but I get error in the line:
Sheets(mysheetname).Column(InAry(Col)).Copy Destination:=Sheets("Volvo_Statistik").Column(OutAry(Col))

runtime error 438'
the object does not support the properties or method
 
Upvote 0
Hi

You could split that line to :-
Code:
Sheets(mysheetname).Column(InAry(Col)).Copy 
Sheets("Volvo_Statistik").Column(OutAry(Col).Paste

hth
 
Upvote 0
Alternatively :-
Code:
 Sheets(mysheetname).Columns(InAry(Col)).Copy Destination:=Sheets("Volvo_Statistik").Columns(OutAry(Col))

hth
 
Upvote 0
I have made a very long code....
But I want to make it shorter, but I don't know how...
This is untested, but I believe the following macro can replace the macro you posted in its entirety...
Code:
[table="width: 500"]
[tr]
	[td]Sub GetColData()
  Dim X As Long, Sht As Worksheet, Target As Worksheet, VS() As String, TS() As String
  Const Vehicles = ",Volvo_3P,VolVo_Penta,Volvo_Bus,Volvo_Business_Service,Volvo_Group_Trucks_Technology,Volvo_Information_Technology_AB,Volvo_Group_Sweden,Volvo_IT"
  Set Target = Sheets("Target_sheet")
  VS = Split("A,C,D,E,G,H,I,J,K,K,M,O", ",")
  TS = Split("A,D,H,I,J,K,L,M,E,F,U,AB", ",")
  For Each Sht In ThisWorkbook.Worksheets
    If InStr(Vehicles, "," & Sht.Name) Then
      For X = 0 To UBound(VS)
        Sht.Columns(VS(X)).Copy Target.Cells(1, TS(X))
      Next
    End If
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
This is untested, but I believe the following macro can replace the macro you posted in its entirety...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub GetColData()
  Dim X As Long, Sht As Worksheet, Target As Worksheet, VS() As String, TS() As String
  Const Vehicles = ",Volvo_3P,VolVo_Penta,Volvo_Bus,Volvo_Business_Service,Volvo_Group_Trucks_Technology,Volvo_Information_Technology_AB,Volvo_Group_Sweden,Volvo_IT"
  Set Target = Sheets("Target_sheet")
  VS = Split("A,C,D,E,G,H,I,J,K,K,M,O", ",")
  TS = Split("A,D,H,I,J,K,L,M,E,F,U,AB", ",")
  For Each Sht In ThisWorkbook.Worksheets
    If InStr(Vehicles, "," & Sht.Name) Then
      For X = 0 To UBound(VS)
        Sht.Columns(VS(X)).Copy Target.Cells(1, TS(X))
      Next
    End If
  Next
End Sub[/TD]
[/TR]
</tbody>[/TABLE]


Awesome works !!!!
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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