从第1行开始,select列F中的第一个空单元格(不使用偏移量)
这是一个我很困惑的查询。 因为我已经找了这么多次,但我总是find相关的代码find最后使用或第一个非空的单元格。 试着在下面的代码。 diff代码已被单词“even”分开
iRow = Worksheets("Sheet1").Cells(Rows.Count,1).End(XlUp).Row
甚至
Sub LastCellBeforeBlankInColumn() Range("A1").End(xldown).Select End Sub
甚至
在列中查找最后使用的单元格:
Sub LastCellInColumn() Range("A65536").End(xlup).Select End Sub
甚至
在一行的空白处find最后一个单元格:
Sub LastCellBeforeBlankInRow() Range("A1").End(xlToRight).Select End Sub
甚至
查找行中最后使用的单元格:
Sub LastCellInRow() Range("IV1").End(xlToLeft).Select End Sub
甚至
Worksheets("Sheet1").Range("A1").End(xlDown).Row + 1
甚至
LastRow = Range("A" & Rows.Count).End(xlUp).Row + 1 Sheets("SheetName").Range("A" & LastRow).Paste
甚至
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
如果你所要做的只是select给定列中的第一个空白单元格 ,你可以试试这个:
码:
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
select之前 – 第一个空白单元格select:
select后:
山姆代码虽然不错,但我认为需要一些修正,
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
谢谢
如果有任何一个人因为我刚才有绊倒…
在列中find第一个空白单元格(我正在使用D列,但不想包含D1)
NextFree = Range("D2:D" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row Range("D" & NextFree).Select
NextFree只是一个名字,你可以用香肠。
如果你所要做的只是select给定列中的第一个空白单元格,你可以试试这个:
Range("A1").End(xlDown).Offset(1, 0).Select
如果你正在寻找一个class轮(不包括名称和评论)试试这个
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
我适应了一下每个人的代码,使它在一个函数,使其更快(数组),并添加参数:
Public Function FirstBlankCell(Optional Sh As Worksheet, Optional SourceCol As Long = 1, Optional ByVal StartRow& = 1, Optional ByVal SelectCell As Boolean = False) As Long Dim RowCount As Long, CurrentRow As Long Dim CurrentRowValue As String Dim Data() If Sh Is Nothing Then Set Sh = ActiveSheet With Sh rowCount = .Cells(.Rows.Count, SourceCol).End(xlUp).Row Data = .Range(.Cells(1, SourceCol), .Cells(rowCount, SourceCol)).Value2 For currentRow = StartRow To RowCount If Data(currentRow, SourceCol) = vbNullString Then If SelectCell Then .Cells(currentRow, SourceCol).Select 'if selection is out of screen, intead of .select , use : application.goto reference:=.cells(...), scroll:= true FirstBlankCell = currentRow Exit For End If Next End With ' Sh Erase Data Set Sh = Nothing End Function
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
如果任何列连续包含多个空单元格,则此代码将无法正常工作