|
changhuijiang 发表于 2014-3-1 20:02 
对,是这个思路,然后我试着写,但是没有写出来,之前就知道一些编程知识,发现真要自己写,没那么简单, ...
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
For j = 1 To 3 '遍历读取txt文件的表
a = 0
For i = 9 To 1 Step -1
Set rng = Sheets(j).Rows(1).Find(Cells(1, i), lookat:=xlWhole)
If Not rng Is Nothing Then
a = a + 1
Sheets(j).Columns(rng.Column).Cut
Sheets(j).Columns("A:A").Insert Shift:=xlToRight
End If
Next i
'k1 = Sheets(j).Cells(1, Columns.Count).End(xlToLeft).Column
If a = 0 Then
Sheets(j).Cells.ClearContents
Else
For l = Sheets(j).Cells(1, Columns.Count).End(xlToLeft).Column To a + 1 Step -1
Sheets(j).Columns(l).Delete
Next l
End If
Next j
Application.ScreenUpdating = True
End Sub |
|