27

これは私が本当に混乱している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
4

14 に答える 14

19

特定の列の最初の空白セルを選択するだけの場合は、これを試してみてください。

コード:

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

選択前-選択する最初の空白セル:

ここに画像の説明を入力してください

選択後:

ここに画像の説明を入力してください

于 2013-02-19T16:09:49.630 に答える
17

特定の列の最初の空白のセルを選択するだけの場合は、これを試してみてください。

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

選択した列に関連して使用している場合、これは機能します。

Selection.End(xlDown).Offset(1, 0).Select
于 2015-11-20T14:16:55.890 に答える
16

私がちょうど持っているように誰かがこれにつまずいた場合に備えて...

列の最初の空白セルを検索します(列Dを使用していますが、D1を含めたくありませんでした)

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

NextFreeは単なる名前であり、必要に応じてソーセージを使用できます。

于 2014-06-25T13:02:19.257 に答える
9

サムのコードは良いですが、修正が必要だと思います。

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

ありがとう

于 2014-04-02T12:52:22.257 に答える
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
于 2016-08-13T01:14:04.387 に答える
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
于 2016-07-05T15:51:21.950 に答える
2

これは非常に高速でクリーンな方法です。また、空の列もサポートしますが、上記の回答はいずれも空の列では機能しませんでした。

使用法:SelectFirstBlankCell("F")

Public Sub SelectFirstBlankCell(col As String)

    Dim i As Integer

    For i = 1 To 10000
        If Range(col & CStr(i)).Value = "" Then
            Exit For
        End If
    Next i

    Range(col & CStr(i)).Select
End Sub
于 2018-05-02T14:26:32.457 に答える
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

いずれかの列に複数の空のセルが連続して含まれている場合、このコードは正しく機能しません

于 2015-04-27T06:37:15.670 に答える
1

同様のタスクを実行しようとしたときに、このスレッドを見つけました。結局、私は使用しました

Range("F:F").SpecialCells(xlBlanks).Areas(1)(1).Select

ワークシートの指定された範囲と使用された範囲の交点に空白のセルがある限り、これは正常に機能します。

areaプロパティは、範囲内の最初の絶対ブランクを見つけるために必要ではありませんが、後続の連続していないブランクを見つけるのに役立ちます。

于 2019-11-16T12:36:18.190 に答える
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
于 2018-09-29T19:30:41.143 に答える
0

空でないセルの前にあるすべての空のセルを無視し、最初の列の最後から最後の空のセルを選択する別の方法があります。列は、その番号でアドレス指定する必要があります。列"A"=1。

With ThisWorkbook.Sheets("sheet1")

        .Cells(.Cells(.Cells.Rows.Count, 1).End(xlUp).Row + 1, 1).select

End With

次のコードは上記とまったく同じですが、よりよく理解できます。

i = ThisWorkbook.Sheets("sheet1").Cells.Rows.Count

j = ThisWorkbook.Sheets("sheet1").Cells(i, 1).End(xlUp).Row

ThisWorkbook.Sheets("sheet1").Cells(j + 1, 1) = textbox1.value
于 2019-09-11T06:40:50.960 に答える
0

NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1

于 2020-04-30T22:19:24.180 に答える
0

選択したセルに基づいて、列で最初に見つかった空のセルを選択するために、このワンライナーを作成しました。選択したセルの最初の列でのみ機能します。必要に応じて変更

Selection.End(xlDown).Range("A2").Select
于 2020-08-06T19:10:52.857 に答える
0

.Findには多くのオプションがあり、範囲内に空のセルが見つからない場合はNothingを返します。

With Range("F:F")
     .Find("", .Rows(.Rows.Count), xlFormulas, , xlByRows, xlNext).Select
End With

.Findは、デフォルトで範囲内の最初のセルの後に検索を開始するため、通常は行2から開始します。After引数が範囲内の最後のセルである場合、行1から始まる最初の空のセルが検索されます。これは、検索が終了するためです。

于 2021-09-08T01:34:19.087 に答える