VBScript每50000行将大型excel文件拆分为较小的文件
我被要求将一个非常大的excel文件1000000+行拆分成更小的excel 用户通过输入框决定的特定行数之后的文件,但在此之前,我必须询问用户是否希望在列的信息存储到变量userCensor后使用另一个输入框将特定列替换为“#####”,然后,我想获取为行拆分输入的数字,将其存储为userSplit,并按照userSplit中指定的间隔拆分文件 这就是我到目前为止所经历的,我目前正在经历一个大的大脑放屁,不知道从这里可以走到哪里:VBScript每50000行将大型excel文件拆分为较小的文件,vbscript,excel-2010,Vbscript,Excel 2010,我被要求将一个非常大的excel文件1000000+行拆分成更小的excel 用户通过输入框决定的特定行数之后的文件,但在此之前,我必须询问用户是否希望在列的信息存储到变量userCensor后使用另一个输入框将特定列替换为“#####”,然后,我想获取为行拆分输入的数字,将其存储为userSplit,并按照userSplit中指定的间隔拆分文件 这就是我到目前为止所经历的,我目前正在经历一个大的大脑放屁,不知道从这里可以走到哪里: Set app = CreateObject("Excel.A
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
这是不多去了,但任何帮助将不胜感激
再次感谢 您可以尝试以下方法将内容分成更小的部分:
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
至于删除列,实际上删除列而不是用其他内容替换列不是更容易吗