0
Sub copycolumns()
Dim y As Workbook
Dim x As Workbook
Dim ws As Worksheet
Dim sh As Worksheet
Set x = Workbooks.Open("C:\Users\hshabbir\Desktop\testing.xlsx")
Set sh = x.Sheets("Sheet2")
Set y = ThisWorkbook
Set ws = y.Sheets("Sheet1")
Application.ScreenUpdating = 0
Dim i As Integer, searchedcolumn As Integer, searchheader As Object
For i = 1 To 8
Set searchheader = ws.Cells(1, i)
searchedcolumn = 0
On Error Resume Next
searchedcolumn = sh.Rows(1).Find(what:=searchheader.Value, lookat:=xlWhole).Column
On Error GoTo 0
If searchedcolumn <> 0 Then
ws.Columns(searchedcolumn).Copy Destination:=searchheader
End If
Next i
x.Close
End Sub
それがコピーされていないデータ –
を動かすために働いていないです得ていないのです列( 'ws.Columns(searchedcolumn).Copy')をセルに挿入しますか? ( 'set searchheader = ws.Cells(1、i)')もしあなたがエラーを処理していなければ何も起こりません。 – RCaetano