How to instruct paste location to another sheet? (I'm searching for col's by header)

SURFER349

Board Regular
Joined
Feb 22, 2017
Messages
50
SO I have this script that searches for a list of columns in a sheet and then pastes them to another sheet in order of the list. However, I can't seem to get it to paste somewhere other than Col1 on the destination sheet. I tried adjusting the # values for (x,y) in the Destination:=wsF.Cells section.

How do I direct this to paste in something like the 8th column, Col H?

VBA Code:
Sub CopyCols() 'copy paste columns
Dim wsO As Worksheet
Dim wsF As Worksheet
Dim i As Integer

Application.ScreenUpdating = False
Set wsO = Worksheets("RawData")
Set wsF = Worksheets("FormatingSheet")
myColumns = Array("Col4", "Col3", "Col7", "Col1")

With wsO.Range("D1:M1")
    For i = 0 To UBound(myColumns)
        On Error Resume Next
        .Find(myColumns(i)).EntireColumn.Copy Destination:=wsF.Cells(1, i + 1)
        Err.Clear
    Next i
End With
Set wsO = Nothing
Set wsF = Nothing
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Glad it worked out. :) The first value in the bracket always refers to the row and the second value to the column.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
Latest member
RandomExceller01

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