这是一个我真的很困惑的问题。因为我已经多次寻找这个,但我总能找到与找到最后一个或第一个非空单元相关的代码。 试过下面的代码。差异代码已被单词“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
甚至
在行中的空白之前找到最后一个单元格:
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
答案 0 :(得分:12)
如果您要做的只是选择给定列中的第一个空白单元格,您可以尝试一下:
<强>代码:强>
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
选择之前 - 要选择的第一个空白单元格:
选择后:
答案 1 :(得分:12)
如果有人因此而绊倒了......
查找列中的第一个空白单元格(我使用的是D列,但不想包含D1)
NextFree = Range("D2:D" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row
Range("D" & NextFree).Select
NextFree只是一个名字,你可以根据需要使用香肠。
答案 2 :(得分:10)
如果你要做的就是选择给定列中的第一个空白单元格,你可以尝试一下:
Range("A1").End(xlDown).Offset(1, 0).Select
如果您相对于您选择的列使用它,则可以使用:
Selection.End(xlDown).Offset(1, 0).Select
答案 3 :(得分:8)
Sam的代码很好,但我认为需要一些修正,
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
由于
答案 4 :(得分:6)
如果您正在寻找一个班轮(不包括名称和评论),请尝试此
RewriteCond %{QUERY_STRING} (^|&)x=12($|&)
RewriteRule ^sample\.php$ /sample/12?&%{QUERY_STRING}
答案 5 :(得分:2)
我对每个人的代码进行了调整,在函数中进行了调整,使其更快(数组),并添加了参数:
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
答案 6 :(得分:1)
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
如果任何列连续包含多个空单元格,则此代码将无法正常工作
答案 7 :(得分:1)
这是一种非常快速和干净的方式。它还支持空列,因为上面的答案都不适用于空列。
用法:SelectFirstBlankCell("F")
Public Sub SelectFirstBlankCell(col As String)
Dim i As Integer
Dim NextCell As Integer
For i = 1 To 10000
If Range(col & CStr(i)).Value = "" Then
NextCell = i
Exit For
End If
Next i
Range(col & CStr(i)).Select
End Sub
答案 8 :(得分:0)
我认为Do Until
循环在这里更干净,更短且更合适:
Public Sub SelectFirstBlankCell(col As String)
Dim Column_Index as Integer
Dim Row_Counter as
Column_Index = Range(col & 1).Column
Row_Counter = 1
Do Until IsEmpty(Cells(Row_Counter, 1))
Row_Counter = Row_Counter + 1
Loop
Cells(Row_Counter, Column_Index).Select
答案 9 :(得分:0)
还有另一种方法可以忽略非空单元格之前的所有空单元格,并从第一列的末尾选择最后一个空单元格。列应以其编号表示,例如。 “ A”列= 1。
Login\ReturnUrl="WhereICameFrom&acr_values=AnotherParameter:MyComputedValue"
下一个代码与上面的代码完全相同,但可以更好地理解。
With ThisWorkbook.Sheets("sheet1")
.Cells(.Cells(.Cells.Rows.Count, 1).End(xlUp).Row + 1, 1).select
End With
答案 10 :(得分:0)
我在尝试执行类似任务时发现了该线程。最后,我用
Range("F:F").SpecialCells(xlBlanks).Areas(1)(1).Select
只要在指定范围和工作表的使用范围相交处有一个空白单元格,这可以正常工作。
不需要Areas属性来找到该范围内的绝对第一个空白,但是对于查找后续的非连续空白很有用。
答案 11 :(得分:0)
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
答案 12 :(得分:0)
我刚刚编写了此单行代码,以基于所选单元格选择在列中找到的第一个空单元格。仅适用于所选单元格的第一列。根据需要修改
Selection.End(xlDown).Range("A2").Select