Nis*_*ant 17 excel vba excel-vba
这是一个我真的很困惑的问题.因为我已经多次寻找这个,但我总能找到与查找最后使用过的或第一个非空单元相关的代码.试过下面的代码.差异代码用"偶数"一词分隔
iRow = Worksheets("Sheet1").Cells(Rows.Count,1).End(XlUp).Row
Run Code Online (Sandbox Code Playgroud)
甚至
Sub LastCellBeforeBlankInColumn()
Range("A1").End(xldown).Select
End Sub
Run Code Online (Sandbox Code Playgroud)
甚至
找到列中最后使用的单元格:
Sub LastCellInColumn()
Range("A65536").End(xlup).Select
End Sub
Run Code Online (Sandbox Code Playgroud)
甚至
在行中的空白之前找到最后一个单元格:
Sub LastCellBeforeBlankInRow()
Range("A1").End(xlToRight).Select
End Sub
Run Code Online (Sandbox Code Playgroud)
甚至
找到行中最后一个使用过的单元格:
Sub LastCellInRow()
Range("IV1").End(xlToLeft).Select
End Sub
Run Code Online (Sandbox Code Playgroud)
甚至
Worksheets("Sheet1").Range("A1").End(xlDown).Row + 1
Run Code Online (Sandbox Code Playgroud)
甚至
LastRow = Range("A" & Rows.Count).End(xlUp).Row + 1
Sheets("SheetName").Range("A" & LastRow).Paste
Run Code Online (Sandbox Code Playgroud)
甚至
Dim FirstBlankCell as Range
Set FirstBlankCell=Range("A" & rows.Count).end(xlup).offset(1,0)
FirstBlankCell.Activate
'Find the last used row in a Column: column A in this example
Dim LastRow As Long
Dim NextRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
End With
NextRow = LastRow + 1
Run Code Online (Sandbox Code Playgroud)
Sto*_*now 15
如果你要做的就是选择给定列中的第一个空白单元格,你可以尝试一下:
码:
Public Sub SelectFirstBlankCell()
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
sourceCol = 6 'column F has a value of 6
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
'for every row, find the first blank cell and select it
For currentRow = 1 To rowCount
currentRowValue = Cells(currentRow, sourceCol).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
Cells(currentRow, sourceCol).Select
End If
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
选择之前 - 要选择的第一个空白单元格:

选择后:

小智 13
万一有人偶然发现这个......
在列中查找第一个空白单元格(我使用的是列D,但不想包含D1)
NextFree = Range("D2:D" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row
Range("D" & NextFree).Select
Run Code Online (Sandbox Code Playgroud)
NextFree只是一个名字,如果你愿意,你可以使用香肠.
小智 12
如果你要做的就是选择给定列中的第一个空白单元格,你可以尝试一下:
Range("A1").End(xlDown).Offset(1, 0).Select
Run Code Online (Sandbox Code Playgroud)
如果您相对于您选择的列使用它,则可以使用:
Selection.End(xlDown).Offset(1, 0).Select
Run Code Online (Sandbox Code Playgroud)
山姆的代码很好,但我认为需要一些修正,
Public Sub SelectFirstBlankCell()
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
sourceCol = 6 'column F has a value of 6
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
'for every row, find the first blank cell and select it
For currentRow = 1 To rowCount
currentRowValue = Cells(currentRow, sourceCol).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
Cells(currentRow, sourceCol).Select
Exit For 'This is missing...
End If
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
谢谢
小智 7
如果您正在寻找一个班轮(不包括指定和评论),请试试这个
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Name")
'find first empty cell in column F (coming up from the bottom) and return row number
iRow = ws.Range("F:F").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
Run Code Online (Sandbox Code Playgroud)