我被要求将一个非常大的excel文件1,000,000+行拆分成更小的excel 用户通过inputBox决定一定数量的行之后的文件,但在此之前,我必须询问用户是否愿意使用另一个inputBox替换带有“#####”的specfic列。列已存储到变量userCensor,然后我想获取为行拆分输入的数字,将其存储为userSplit并按userSplit中指定的间隔拆分文件。
这是我到目前为止所做的事情,目前我正在经历一个重要的脑屁,并且不知道从哪里开始:
Set app = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
For Each f In fso.GetFolder("Y:\BLAHBLAHBLAH").Files
If LCase(fso.GetExtensionName(f)) = "xls" Then
Set wb = app.Workbooks.Open(f.Path)
set sh = wb.Sheets("Sheet 1") row = 1
lastRow = sh.UsedRange.Rows.Count
lastColumn = sh.UsedRange.Columns.Count
strRow = lastRow
userSplit = InputBox("Enter when you want to split between 1 - " + strRow)
strColumn = lastColumn
userCensor = InputBox("Enter Columns to censor (Format example: 'A:A' deletes column A) Between 1 - " + strColumn)
If userCensor.IsNumeric Then Columns(userCensor).Select
Selection.Replace("######")
For r = row to LastRow If lastColumn > 1 Then
Else
没什么可走的,但任何帮助都会非常感激!
再次感谢!
答案 0 :(得分:3)
您可以尝试使用此类内容将内容分成更小的部分:
firstRow = ws.UsedRange.Rows(1).Row
lastRow = ws.UsedRange.Rows(ws.UsedRange.Rows.Count).Row
userSplit = CLng(InputBox("Enter when you want to split between 1 - " _
& lastRow-firstRow+1))
n = 0
For srcRow = firstrow To lastrow
dstRow = (srcRow - firstRow) Mod userSplit + 1
If dstRow = 1 Then
n = (srcRow - firstRow) \ userSplit
If n > 0 Then
wb2.SaveAs "C:\path\to\out" & n & ".xls"
wb2.Close
End If
Set wb2 = xl.Workbooks.Add
End If
ws1.Cells(srcRow, 1).EntireRow.Copy
wb2.Sheets(1).Cells(dstRow, 1).PasteSpecial xlAll
Next
wb2.SaveAs "C:\path\to\out" & (lastRow - firstRow) \ userSplit & ".xls"
wb2.Close
至于删除列,实际删除列而不是用其他内容替换其内容会不会更容易?