Подтвердить что ты не робот

Выберите первую пустую ячейку в столбце F, начиная с строки 1. (без использования смещения)

Это один вопрос, с которым я действительно смущен. Coz Я искал это столько раз, но всегда нашел коды, связанные с поиском последней использованной или первой не пустой ячейки. Пробовали по кодам ниже. Дифференциальные коды были разделены словом "четный"

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
4b9b3361

Ответ 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

Перед выбором - первая пустая ячейка для выбора:

enter image description here

После выбора:

enter image description here

Ответ 2

Если кто-то наткнется на это, как я просто...

Найти первую пустую ячейку в столбце (я использую столбец D, но не хочу включать D1)

NextFree = Range("D2:D" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row
Range("D" & NextFree).Select

NextFree - это просто имя, вы можете использовать колбасы, если хотите.

Ответ 3

Код Сэма хорош, но я думаю, что ему нужна коррекция,

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

Если все, что вы пытаетесь сделать, это выбрать первую пустую ячейку в данном столбце, вы можете попробовать:

Range("A1").End(xlDown).Offset(1, 0).Select

Ответ 5

Если вы ищете один вкладыш (не включая обозначения и комментарии), попробуйте это

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

Ответ 6

Я немного адаптировал код каждого, сделал его в функции, сделал его быстрее (массив) и добавил параметры:

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

Ответ 7

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

Если какой-либо столбец содержит более одной пустой ячейки, то этот код не будет работать должным образом