使用vba excel查找最后一个单元格地址 [英] Find the last cell address using vba excel

查看:375
本文介绍了使用vba excel查找最后一个单元格地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索过这个网站,似乎所有的答案只是指出找到单元格的行号。

I have searched this site and it seems like all the answers just point to finding the row number of the cell.

我正在设置一个范围,以便它将从 A1 转到 A 列中数据的末尾。此电子表格将每周更新一次,因此每周都会添加数据。

I am trying to set a range so that it will go from A1 to the end of the data in the A column. This spreadsheet will be updated weekly so there will be data added to it every week.

我想知道什么代码可以工作,以便我可以找到行号,并以某种方式与我的范围代码绑定,以便它将等于A+ lastrownumber ?或者如果有代码将提供列和行号在一起?如果我错过了正确答案的链接,一个简单的链接也会这样做,对于帖子和你的时间我很抱歉。

I was wondering what code would work so that I can either find the row number and somehow tie it in with my range code so that it will equal "A" + lastrownumber? OR if there is code that will provide the column and row number together? If I have missed the link to the correct answer a simple link will do as well and I apologize for the post and your time.

这是我的代码:

Sub NamedRange()

Dim Rng1 As Range
Dim newDate As Integer
Dim NumberOfRows As Range


Dim MyRange As Range
Dim lastRow2 As Range


lastRow2 = Range("A65536").End(xlUp).Row
'lastRow2 = LastRow

Set Rng1 = Sheets("Sheet1").Range(lastRow2)
ActiveWorkbook.Names.Add Name:="MyRange", RefersTo:=Rng1


Dim date1 As String
Dim dat As Date
Dim newPrice As Double


Set RgSales = Range("MyRange")


推荐答案

对应于列A中最后一个填充单元格的范围对象

This will return the range object corresponding to the last filled in cell in column A

Range("A:A").Find("*",Range("A1"),SearchDirection:=xlprevious)

如果你想要行号,我们以下内容:

If you want the row number, use the following:

Range("A:A").Find("*",Range("A1"),SearchDirection:=xlprevious).row

这篇关于使用vba excel查找最后一个单元格地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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