查找Excel工作表中的最后一个单元格? [英] Finding the last cell in an excel sheet?

查看:14
本文介绍了查找Excel工作表中的最后一个单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆