求一段excel vba代码!实现以下功能
发布网友
发布时间:2022-04-24 16:11
我来回答
共3个回答
热心网友
时间:2022-04-21 00:42
不知 选择性粘贴 的哪一项能删除单元格中的空格?
我在前不久编了与你说的类似的宏。为了达到你的要求,可能要适当修改。请hi 我
'新建一Excel文件,把代码粘进去,执行,按提示操作
Sub 删除空格()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
BkName = ActiveWorkbook.Name
MsgBox "请选择 Excel文件 的路径!"
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
folderspec = .SelectedItems(1)
If Right(SavePath, 1) <> "\" Then
folderspec = folderspec + "\"
End If
End With
Dim fs, f, f1, fc
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
sc = 1
Dim ran As Range
For Each f1 In fc
If Right(f1.Name, 3) = "xls" Then
fName = folderspec + f1.Name
' sName = Left(f1.Name, Len(f1.Name) - 4)
Workbooks.Open fName
For s = 1 To Sheets.Count
Sheets(s).Select
Set ran = Cells(1, 1).CurrentRegion
Row = ran.Rows.Count
col = ran.Columns.Count
For r = 1 To Row
For c = 1 To col
Cells(r, c) = Trim(Cells(r, c))
Next c
Next r
Next s
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "空格删除完毕!"
End Sub
热心网友
时间:2022-04-21 02:00
用代码没试过,提供以下手动方法(前提是原表格不含公式):
1,打开原文件
2,新建一个文件
3,在新文件的A1单元格 =If(点到原文件A1="","",点到原文件A1),回车
4,复制新A1,Ctrl+A,Ctrl+V,这样就用公式将原表中导入新表
5,新表中Ctrl+A,Ctrl+C,右建 - 选择性粘贴,数值
热心网友
时间:2022-04-21 03:35
楼主的问题可行性蛮高滴,只是有人会用太多时间来百度空间做这个工作量不少的事么。