简体   繁体   中英

Select only cells with data but skip the first cell in a column

I am currently using this script.

Range("E2").Select
Range(Selection, Selection.End(xlDown)).Select
For Each xCell In Selection
xCell.Value = CDec(xCell.Value)
Next xCell

I want to only select the cells in column E that have data, but the amount of cells that have data varies, and I don't want to select E1 because it has a header. This code changes the foreign text in column E to numbers that I can actually use the sum function to add up. The way it is written now it puts a 0 in all of the cells in the column infinitely.

Try following code:

Dim lastrow As Long

lastrow = Application.Max(2, Cells(Rows.Count, "E").End(xlUp).Row)

With Range("E2:E" & lastrow)
    .NumberFormat = "0"
    .Value = .Value
End With

UPD:

if it doesn't help, try this:

Dim lastrow As Long

lastrow = Application.Max(2, Cells(Rows.Count, "E").End(xlUp).Row)

For i = 2 To lastrow
    With Range("E" & i)
        .Value = CDec(.Value)
    End With
Next

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