Excel指定文件夾批量刪除指定列


Excel-文件-選項-自定義功能區-開發工具(勾選)

開發工具-Visual Basic

注意:刪除列時只能倒序刪除

暫時還不會刪除合並單元格:Selection.MergeCells

Sub Del_Col() Application.DisplayAlerts = False Dim myFiles As String Dim myExcels As String With Application.FileDialog(msoFileDialogFolderPicker) .Show .AllowMultiSelect = False .Title = "請選擇要刪除列的文件所在文件夾" myFiles = .SelectedItems(1) End With myExcels = Dir(myFiles & "\" & "*.xls*")
Do While Len(myExcels) <> 0 Workbooks.Open (myFiles & "\" & myExcels)
 Worksheets(1).Columns("H:H").Delete Worksheets(1).Columns("F:F").Delete Worksheets(1).Columns("E:E").Delete Worksheets(1).Columns("C:C").Delete Worksheets(1).Columns("B:B").Delete ActiveWorkbook.Save Workbooks(2).Close myExcels = Dir Loop Application.DisplayAlerts = True MsgBox "刪除完成" End Sub

 

厲害的excel方法:

Sub 取消合並且填充() ' ' 取消合並且填充 Macro ' 宏由 James 錄制,時間: 2008-5-15 ' 說明:不管三七二十一,一次性把當前工作表中所有的合並單元格都搞掂!宏從第一列開始逐列搜索直到遇到空列停止 ' 宏會檢查連續且有數據的所有格子,如果其中有空格,那就不同了: ' 對於數據中有空格:如果500行以下有空格,則宏忽略501行以下的格子。這個“500”在程序是可以看到的,可以手工改變它。
 Dim find As Boolean, i As Integer Application.CutCopyMode = False Cells(1, 1).Select While ActiveCell.Text <> "" find = False i = 1 If Selection.MergeCells Then Selection.UnMerge i = Selection.Areas(1).Rows.Count If i > 1 Then Selection.FillDown If Selection.Areas(1).Columns.Count > 1 Then Selection.FillRight End If ActiveCell.Offset(i, 0).Range("A1").Select While (Selection.Range("A1").Text <> "" And Not find) Or (Selection.Range("A1").Text = "" And ActiveCell.Row() < 500) If Selection.MergeCells Then find = True If Not find Then ActiveCell.Offset(1, 0).Range("A1").Select Wend If Not find Then ActiveCell.Offset(0, 1).Range("A1").Select Cells(1, ActiveCell.Column()).Select End If Wend End Sub Private Sub CommandButton1_Click() 取消合並且填充 End Sub

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM