简体   繁体   中英

Range of cells in VBA Excel

I have a question regarding range of cells in VBA in Excel. What I am trying to do is write a VBA code that selects a range of values from an initial value that I supply all the way to the bottom of the column, where the last entry is.

I defined my initial value as:

Dim Value_one As Integer
Value_one = 8

Now I can't seem to find a code that selects a range of values in a column starting at 8th row to the last cell in that column. I tried this:

Range(Value_one, Value_one.End(xlDown)).Select

But it didn't work. Any help would be much appreciated!

Two answers:

Sub ToTheVeryBottom()
    Dim Value_one As Integer
    Value_one = 8
    Range("A" & Value_one & ":A" & Rows.Count).Select
End Sub

will select from row #8 through row #1048576. However:

Sub ToTheLastItem()
    Dim Value_one As Integer, N As Long
    Value_one = 8
    N = Cells(Rows.Count, "A").End(xlUp).Row
    Range("A" & Value_one & ":A" & N).Select
End Sub

will select from row #8 through the last row containing some value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM