在Excel表中找到最后一个单元格? [英] Finding the last cell in an excel sheet?
问题描述
我正在使用vb6并将数据复制到Excel表格中。我需要做的是将数据附加到现有工作表。我正在找到我需要找到工作表中最后一个单元格的索引号(只有一个工作表)。我已经尝试了几个东西,如 oBook.range.cells.specialcells(xllastcell )
但无济于事。我现在打开我想要的工作表是这个
I'm using vb6 and copying data to an excel sheet. What I need to do is append data to an existing sheet. I am at the point where I need to find the index number of the last cell in the sheet (there's only one sheet.) I've tried a couple things like oBook.range.cells.specialcells(xllastcell)
but to no avail. What I have right now to open the worksheet I want is this
If Not Dir(strPath) = "" Then
Set oExcel = CreateObject("Excel.application")
Set oBook = oExcel.workbooks.open(strPath)
但我不知道从这里做什么来找到工作簿中的最后一个单元格。
but I have no idea what to do from here to find the last cell in the workbook.
推荐答案
在互联网冲浪的答案我发现一行代码工作。我必须将一些值,例如 xlbyrows
更改为1和 xlprevious
为2,因为vb6 dows
Upon scouring the internet for the answer I found a line of code that worked. I had to change some of the values such as xlbyrows
to "1" and xlprevious
to "2" because vb6 dows not recognize the terms but can use the number constants.
这是代码的原始代码
LastRow = Cells.Find("*",SearchOrder:=xlByRows,SearchDirection:=xlPrevious).Row
这是我改变了它与我的代码一起使用
this is what I changed it to that worked with my code
iCell = oExcel.cells.find("*", searchorder:=1, searchdirection:=2).row
这篇关于在Excel表中找到最后一个单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!