如何删除Excel结尾处的空行

时间:2018-11-28 12:49:44

标签: excel vbscript

我编译了一个excel实用程序,将一个大文件拆分为多个较小的文件,在我的情况下为100k行。但是,最后一个文件显示了10万行,尽管直到10万行才显示数据。如何删除最后一个分区的文件末尾的空白行。

这是我的代码。

   Set objWorkbook = objExcel.Workbooks.Open(filePath) 

  'Initialize data  
   Set ThisSheet = objWorkbook.ActiveSheet

  'Getting number of columns and rows for calculation
   NumOfColumns = ThisSheet.UsedRange.Columns.Count
   rowCount = ThisSheet.UsedRange.Rows.Count  

   WorkbookCounter = 1
   RowsInFile = 100000      

     If rowCount > 100000 Then
      ' extracting the file name alone.
       fName = Left(fileName, (InStrRev(fileName, ".") - 1)) ' file name  
      ' Copy the data of the first row (header)
      Set RangeOfHeader = ThisSheet.Range(ThisSheet.Cells(1, 1), ThisSheet.Cells(1, NumOfColumns))

     'Create the file system object for creating folders
     Set objFSO = CreateObject("Scripting.FileSystemObject")    

    'extracting the path name excluding the file name
     newPath = CStr(Left(filePath, InStrRev(filePath, "\")))     
     folderName = newPath & "Copy_of_" & fName & "\"     
     'Create the folders using objFSO
     'First check if folders exists and create only they dont exist
     if Not objFSO.FolderExists(folderName) Then      
       objFSO.CreateFolder(folderName)
     Else
       WScript.Echo "Folder already Exists"
   End If    

当我选择Ctrl + Shift +向下箭头时。count显示文件。当我单击Ctrl + End按钮时..控件转到第100k行...并且上面的许多行都是空白的。理想情况下,Ctrl + End应该在数据结束处停止。

非常感谢指针,并在此先感谢。

1 个答案:

答案 0 :(得分:0)

我不是100%肯定,但是我相信这将计算在excel文件中分配的空行。

redirect-uri

尝试使用此代替:

rowCount = ThisSheet.UsedRange.Rows.Count