使用VBA重新排列多个Excel文件中的列

使用VBA重新排列多个Excel文件中的列,vba,excel,Vba,Excel,我在重新排列多个Excel文件中的列时遇到问题。我有312个文件,每个文件有200列。我想按特定的顺序排列列,以便合并所有文件以创建主文件。我有VBA代码,可以在一个Excel文件中重新排列列。我想让代码在所有文件中循环,重新排列列,保存并关闭工作簿 Sub MoveColumns() strName = Dir(File_Path & "\" & "*.csv") 'CHANGE FILE EXTENSION TO OTHER EXCEL BASED EXTENSION I

我在重新排列多个Excel文件中的列时遇到问题。我有312个文件,每个文件有200列。我想按特定的顺序排列列,以便合并所有文件以创建主文件。我有VBA代码,可以在一个Excel文件中重新排列列。我想让代码在所有文件中循环,重新排列列,保存并关闭工作簿

Sub MoveColumns()
strName = Dir(File_Path & "\" & "*.csv")  'CHANGE FILE EXTENSION TO OTHER  EXCEL BASED EXTENSION IF YOU WANT
Dim iRow As Long
Dim iCol As Long
Do While strName <> vbNullString
If active_workbook.Name <> strName And strName <> "" Then
    Workbooks.Open Filename:=File_Path & "\" & strName
    Set dataset_workbook = ActiveWorkbook
'Constant values
ActiveWorksheet = Sheets(1)
target_sheet = "Final Report" 'Specify the sheet to store the results
iRow = Sheets(ActiveWorksheet).UsedRange.Rows.Count 
Worksheets.Add.Name = "Final Report"

For iCol = 1 To Sheets(ActiveWorksheet).UsedRange.Columns.Count

'Sets the TargetCol to zero in order to prevent overwriting existing targetcolumns
TargetCol = 0

'Read the header of the original sheet to determine the column order
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Source" Then TargetCol = 1
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Business Name" Then TargetCol = 2
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Legal Name" Then TargetCol = 3
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Physical Address" Then TargetCol = 4
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Physical Address Number" Then TargetCol = 5
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Physical Pre Direction" Then TargetCol = 6
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Physical Address Name" Then TargetCol = 7
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Physical Address Suffix" Then TargetCol = 8
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Physical Post Direction" Then TargetCol = 9
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Physical City" Then TargetCol = 10
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Physical State" Then TargetCol = 11
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Physical ZIP" Then TargetCol = 12
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Physical ZIP 4" Then TargetCol = 13
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Key Executive Name" Then TargetCol = 14
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "First Name" Then TargetCol = 15
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Middle Initial" Then TargetCol = 16
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Last Name" Then TargetCol = 17
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Title" Then TargetCol = 18
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Gender" Then TargetCol = 19
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Location Employee Size" Then TargetCol = 20
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Corporate Employee Size" Then TargetCol = 21
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Revenue / Yr" Then TargetCol = 22
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Mailing Address" Then TargetCol = 23
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Mailing Address Number" Then TargetCol = 24
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Mailing Pre Direction" Then TargetCol = 25
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Mailing Address Name" Then TargetCol = 26
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Mailing Address Suffix" Then TargetCol = 27
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Mailing Post Direction" Then TargetCol = 28
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Mailing City" Then TargetCol = 29
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Mailing State" Then TargetCol = 30
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Mailing ZIP" Then TargetCol = 31
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Mailing ZIP 4" Then TargetCol = 32
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Phone" Then TargetCol = 33
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Fax" Then TargetCol = 34
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Toll-Free" Then TargetCol = 35
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "County Name" Then TargetCol = 36
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "County Population" Then TargetCol = 37
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Metro Area" Then TargetCol = 38
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Latitude" Then TargetCol = 39
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Longitude" Then TargetCol = 40
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "EIN" Then TargetCol = 41
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Main Line of Business" Then TargetCol = 42
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Franchise" Then TargetCol = 43
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Location Type" Then TargetCol = 44
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Importer or Exporter" Then TargetCol = 45
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Manufacturer" Then TargetCol = 46
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Primary SIC" Then TargetCol = 47
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Primary SIC Description" Then TargetCol = 48
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC02" Then TargetCol = 49
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC02.Description" Then TargetCol = 50
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC03" Then TargetCol = 51
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC03.Description" Then TargetCol = 52
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC04" Then TargetCol = 53
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC04.Description" Then TargetCol = 54
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC05" Then TargetCol = 55
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC05.Description" Then TargetCol = 56
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC06" Then TargetCol = 57
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC06.Description" Then TargetCol = 58
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC07" Then TargetCol = 59
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC07.Description" Then TargetCol = 60
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC08" Then TargetCol = 61
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC08.Description" Then TargetCol = 62
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC09" Then TargetCol = 63
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC09.Description" Then TargetCol = 64
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC10" Then TargetCol = 65
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "SIC10.Description" Then TargetCol = 66
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 1" Then TargetCol = 67
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 1 Description" Then TargetCol = 68
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 2" Then TargetCol = 69
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 2 Description" Then TargetCol = 70
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 3" Then TargetCol = 71
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 3 Description" Then TargetCol = 72
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 4" Then TargetCol = 73
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 4 Description" Then TargetCol = 74
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 5" Then TargetCol = 75
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 5 Description" Then TargetCol = 76
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 6" Then TargetCol = 78
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 6 Description" Then TargetCol = 79
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 7" Then TargetCol = 80
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 7 Description" Then TargetCol = 81
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 8" Then TargetCol = 82
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 8 Description" Then TargetCol = 83
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 9" Then TargetCol = 84
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 9 Description" Then TargetCol = 85
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 10" Then TargetCol = 86
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 10 Description" Then TargetCol = 87
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Non-Profit" Then TargetCol = 88
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 2 Description" Then TargetCol = 70
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 3" Then TargetCol = 71
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 3 Description" Then TargetCol = 72
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 4" Then TargetCol = 73
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 4 Description" Then TargetCol = 74
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 5" Then TargetCol = 75
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 5 Description" Then TargetCol = 76
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 6" Then TargetCol = 78
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 6 Description" Then TargetCol = 79
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 7" Then TargetCol = 80
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 7 Description" Then TargetCol = 81
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 8" Then TargetCol = 82
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 8 Description" Then TargetCol = 83
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 9" Then TargetCol = 84
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 9 Description" Then TargetCol = 85
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 10" Then TargetCol = 86
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "NAICS 10 Description" Then TargetCol = 87
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Non-Profit" Then TargetCol = 88
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Number of PCs" Then TargetCol = 89
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Public / Private" Then TargetCol = 90
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Home Based Business" Then TargetCol = 91
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Small Business" Then TargetCol = 92
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Square Footage" Then TargetCol = 93
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Website" Then TargetCol = 94
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Women Owned" Then TargetCol = 95
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Year of Incorporation" Then TargetCol = 96
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Ticker Symbol" Then TargetCol = 97
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Stock Exchange" Then TargetCol = 98
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Fortune 1000 Ranking" Then TargetCol = 99
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Credit Score" Then TargetCol = 100
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "2014 Revenue/Yr" Then TargetCol = 101
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "2012 Revenue/Yr" Then TargetCol = 102
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "2010 Revenue/Yr" Then TargetCol = 103
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "3 Year % Sales Growth" Then TargetCol = 104
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "5 Year % Sales Growth" Then TargetCol = 105
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "2014 Employees" Then TargetCol = 106
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "2012 Employees" Then TargetCol = 107
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "2010 Employees" Then TargetCol = 108
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "3 Year % Employee Growth" Then TargetCol = 109
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "5 Year % Employee Growth" Then TargetCol = 110
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 1" Then TargetCol = 111
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 1" Then TargetCol = 112
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 1" Then TargetCol = 113
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 1" Then TargetCol = 114
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 2" Then TargetCol = 115
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 2" Then TargetCol = 116
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 2" Then TargetCol = 117
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 2" Then TargetCol = 118
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 3" Then TargetCol = 119
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 3" Then TargetCol = 120
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 3" Then TargetCol = 121
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 3" Then TargetCol = 122
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 4" Then TargetCol = 123
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 4" Then TargetCol = 124
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 4" Then TargetCol = 125
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 4" Then TargetCol = 126
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 5" Then TargetCol = 127
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 5" Then TargetCol = 128
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 5" Then TargetCol = 129
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 5" Then TargetCol = 130
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 6" Then TargetCol = 131
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 6" Then TargetCol = 132
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 6" Then TargetCol = 133
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 6" Then TargetCol = 134
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 7" Then TargetCol = 135
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 7" Then TargetCol = 136
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 7" Then TargetCol = 137
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 7" Then TargetCol = 138
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 8" Then TargetCol = 139
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 8" Then TargetCol = 140
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 8" Then TargetCol = 141
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 8" Then TargetCol = 142
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 9" Then TargetCol = 143
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 9" Then TargetCol = 144
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 9" Then TargetCol = 145
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 9" Then TargetCol = 146
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 10" Then TargetCol = 147
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 10" Then TargetCol = 148
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 10" Then TargetCol = 149
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 10" Then TargetCol = 150
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 11" Then TargetCol = 151
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 11" Then TargetCol = 152
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 11" Then TargetCol = 153
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 11" Then TargetCol = 154
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 12" Then TargetCol = 155
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 12" Then TargetCol = 156
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 12" Then TargetCol = 157
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 12" Then TargetCol = 158
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 13" Then TargetCol = 159
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 13" Then TargetCol = 160
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 13" Then TargetCol = 161
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 13" Then TargetCol = 162
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 14" Then TargetCol = 163
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 14" Then TargetCol = 164
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 14" Then TargetCol = 165
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 14" Then TargetCol = 166
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 15" Then TargetCol = 167
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 15" Then TargetCol = 168
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 15" Then TargetCol = 169
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 15" Then TargetCol = 170
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 16" Then TargetCol = 171
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 16" Then TargetCol = 172
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 16" Then TargetCol = 173
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 16" Then TargetCol = 174
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 17" Then TargetCol = 175
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 17" Then TargetCol = 176
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 17" Then TargetCol = 177
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 17" Then TargetCol = 178
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 18" Then TargetCol = 179
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 18" Then TargetCol = 180
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 18" Then TargetCol = 181
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 18" Then TargetCol = 182
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 19" Then TargetCol = 182
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 19" Then TargetCol = 183
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 19" Then TargetCol = 184
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 19" Then TargetCol = 185
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive First Name 20" Then TargetCol = 186
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Last Name 20" Then TargetCol = 187
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Title 20" Then TargetCol = 188
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Executive Gender 20" Then TargetCol = 189
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Est. Accounting Annual Expense" Then TargetCol = 190
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Est. Advertising Annual Expense" Then TargetCol = 191
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Est. Business Insurance Annual Expense" Then TargetCol = 192
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Est. Legal Annual Expense" Then TargetCol = 193
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Est. Office Equipment Annual Expense" Then TargetCol = 194
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Est. Rent Annual Expense" Then TargetCol = 195
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Est. Technology Annual Expense" Then TargetCol = 196
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Est. Telecom Annual Expense" Then TargetCol = 197
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Est. Utilities Annual Expense" Then TargetCol = 198
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "Date" Then TargetCol = 199
If Sheets(ActiveWorksheet).Cells(1, iCol).Value = "AtoZ ID" Then TargetCol = 200

'If a TargetColumn was determined (based upon the header information) then copy the column to the right spot
If TargetCol <> 0 Then
    'Select the column and copy it
    Sheets(ActiveWorksheet).Range(Sheets(ActiveWorksheet).Cells(1, iCol), Sheets(ActiveWorksheet).Cells(iRow, iCol)).Copy     Destination:=Sheets(target_sheet).Cells(1, TargetCol)
End If
   Next iCol 'Move to the next column until all columns are read
   End If
   strName = Dir
   Loop
   Application.DisplayAlerts = True
   End Sub
Sub-MoveColumns()
strName=Dir(文件路径&“\”&“*.csv”)'如果需要,请将文件扩展名更改为其他基于EXCEL的扩展名
暗淡无光
如长
当strName为空字符串时执行
如果是活动的_workbook.Name strName和strName“”,则
工作簿。打开文件名:=文件\路径&“\”&strName
设置数据集\u工作簿=活动工作簿
“常量值
活动工作表=工作表(1)
target_sheet=“Final Report”'指定用于存储结果的工作表
iRow=工作表(活动工作表)。UsedRange.Rows.Count
Worksheets.Add.Name=“最终报告”
对于iCol=1的工作表(活动工作表)。使用drange.Columns.Count
'将TargetCol设置为零,以防止覆盖现有的targetcolumns
TargetCol=0
'读取原始工作表的标题以确定列顺序
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“Source”,则TargetCol=1
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“业务名称”,则TargetCol=2
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“合法名称”,则TargetCol=3
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“物理地址”,则TargetCol=4
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“物理地址号”,则TargetCol=5
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“物理预处理方向”,则TargetCol=6
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“物理地址名称”,则TargetCol=7
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“物理地址后缀”,则TargetCol=8
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“Physical Post Direction”,则TargetCol=9
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“物理城市”,则TargetCol=10
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“物理状态”,则TargetCol=11
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“Physical ZIP”,则TargetCol=12
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“Physical ZIP 4”,则TargetCol=13
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“Key Executive Name”,则TargetCol=14
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“First Name”,则TargetCol=15
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“中间首字母”,则TargetCol=16
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“Last Name”,则TargetCol=17
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“Title”,则TargetCol=18
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“性别”,则TargetCol=19
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“位置员工大小”,则TargetCol=20
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“公司员工人数”,则TargetCol=21
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“收入/年”,则TargetCol=22
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“邮寄地址”,则TargetCol=23
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“邮寄地址编号”,则TargetCol=24
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“邮件预处理方向”,则TargetCol=25
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“邮寄地址名称”,则TargetCol=26
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“邮寄地址后缀”,则TargetCol=27
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“邮件投递方向”,则TargetCol=28
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“邮寄城市”,则TargetCol=29
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“邮寄状态”,则TargetCol=30
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“邮寄ZIP”,则TargetCol=31
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“邮寄ZIP 4”,则TargetCol=32
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“电话”,则TargetCol=33
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“传真”,则TargetCol=34
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“免费”,则TargetCol=35
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“郡名”,则TargetCol=36
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“县人口”,则TargetCol=37
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“Metro Area”,则TargetCol=38
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“纬度”,则TargetCol=39
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“经度”,则TargetCol=40
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“EIN”,则TargetCol=41
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“主要业务线”,则TargetCol=42
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“特许经营”,则TargetCol=43
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“位置类型”,则TargetCol=44
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“导入器或导出器”,则TargetCol=45
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“制造商”,则TargetCol=46
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“主要SIC”,则TargetCol=47
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“主要SIC描述”,则TargetCol=48
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“SIC02”,则TargetCol=49
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“SIC02.Description”,则TargetCol=50
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“SIC03”,则TargetCol=51
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“SIC03.Description”,则TargetCol=52
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“SIC04”,则TargetCol=53
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“SIC04.Description”,则TargetCol=54
如果是工作表(ActiveWorksheet).Cells(1,iCol).Value=“SIC05”,则TargetCol=55
我
Do While Len(strName) > 0
Public Sub Jonah()

    Dim c&, sPath$, sFile$, v, rOut As Range, wbReport As Workbook

    On Error Resume Next
    sPath = "D:\List\List\"
    sFile = Dir(sPath & "*.csv")

    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    With Sheets("template")
        c = .Cells(1, .Columns.Count).End(xlToLeft).Column
        v = .[a1].Resize(, c)
        .Copy
    End With
    Set wbReport = ActiveWorkbook
    wbReport.Sheets(1).Name = "Final Report"
    With wbReport.Worksheets.Add
        .Name = "Tmp"
        Set rOut = .[a1].Resize(, c)
        rOut = v
    End With
    Do
        With Workbooks.Open(sPath & sFile)
            With .Worksheets(1)
                With .[a1].CurrentRegion.Resize(, c + 1)
                    .AdvancedFilter xlFilterCopy, , rOut
                    rOut.CurrentRegion.Resize(, 1).Offset(, c) = .Parent.Name
                    v = rOut.CurrentRegion.Resize(, c + 1).Offset(1)
                    With wbReport.Sheets("Final Report")
                        .Cells(.Rows.Count, "A").End(xlUp)(2).Resize(UBound(v, 1), UBound(v, 2)) = v
                    End With
                    rOut.CurrentRegion.Resize(, c + 1).Offset(1).ClearContents
                End With
            End With
            .Close 0
        End With
        sFile = Dir
    Loop Until sFile = ""
    With wbReport.Sheets("Final Report")
        .[a1].Offset(, c) = "CSV"
        .Cells.EntireColumn.AutoFit
    End With
    wbReport.Sheets("Tmp").Delete
    Application.DisplayAlerts = False
    Application.ScreenUpdating = True

End Sub