2013-02-19 7 views
12

Bu, gerçekten kafamın karıştığı bir sorudur. Coz Bunu pek çok kez aradım ama her zaman en son kullanılmış veya ilk boş olmayan hücreyi bulmakla ilgili kodları bulurum. Aşağıdaki kodlarda denendi. HattaSatır 1'den başlayarak F sütunundaki ilk boş hücreyi seçin (ofset kullanmadan)

Sub LastCellInColumn() 

Range("A65536").End(xlup).Select 

End Sub 

: diff kodları kelime "hatta"

iRow = Worksheets("Sheet1").Cells(Rows.Count,1).End(XlUp).Row 

bile

Sub LastCellBeforeBlankInColumn() 

Range("A1").End(xldown).Select 

End Sub 

bile

Bir Tüp İçinde çok son kullanılan hücreyi bul ayrılmış olan

Bul Bir Satır boş önceki son hücre,:

Sub LastCellInRow() 

Range("IV1").End(xlToLeft).Select 

End Sub 

bile bile

Worksheets("Sheet1").Range("A1").End(xlDown).Row + 1 

:

Sub LastCellBeforeBlankInRow() 

Range("A1").End(xlToRight).Select 

End Sub 

bile

Bir Satır çok son kullanılan hücreyi bul

LastRow = Range("A" & Rows.Count).End(xlUp).Row + 1 
Sheets("SheetName").Range("A" & LastRow).Paste 

bile

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

bunu gördün mü deneyin (belirtme ve yorumlar hariç) bir astar arıyorsanız? http://stackoverflow.com/questions/11169445/error-finding-last-used-cell-in-vba –

+0

Aynı şey değil. İlk boş hücreyi seçmek veya etkinleştirmek istiyorum. örnek: Eğer F5 hücresine kadar değerler varsa o zaman Hücre F6'yı etkinleştirmek istiyorum ve – Nishant

+0

'u kullanırken Offset'i kullanmayın. Eğer son satırı biliyorsanız, o zaman sadece 'Range' ("F" & LastRow) kullanın. " –

cevap

9

Eğer belirli bir sütunda ilk boş hücreyi seçmek olduğunu yapmaya çalışıyoruz tüm bu deneyin yapabiliyorsanız:

Kodu:

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 

Seçimden Önce - ilk boş hücre seçmek için:

Seçim sonrası

enter image description here

:

enter image description here

+1

Hey Teşekkürler Sam Bu benim yapmaya çalıştığım şey. Yine de Siddharth'ın önerisine baktım ve o da çalıştı ve zaten kullandı. Ama senin ansın benim için gelecekte yararlı olur. teşekkürler alot – Nishant

+1

VBA yerine bir formül olarak bunu yapmak için bir yolu var mı? – Raj

7

Sam Kod iyidir ama bazı düzeltme gerektiğini düşünüyorum,

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 

Teşekkür durumda herhangi birinde

+2

ve Uzun Tamsayı yerine kullanmak isteyebilirsiniz, çünkü satırlar çok aşağı gidebilir (veya yukarı?) –

10

bir yanılmak Sadece olduğu gibi bu üzerine s ...

bir sütunda ilk boş hücreyi (I kolon D kullanıyorum ama D1 dahil etmek istemiyordu)

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

NextFree sadece bir isim bulun, İstersen sosis kullanabilirsin.

+0

ilk iki çözüm işe yaramadı, bu bir – Kyoujin

0
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 

herhangi bir sütun belirli bir sütunda ilk boş hücreyi seçmek olduğunu yapmaya çalışıyoruz tüm, verebilirsiniz Birden fazla boş hücre sürekli sonra bu kodu düzgün

4

çalışmaz içeriyorsa Bu deneyin:

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

Bugüne kadar en basit cevap. – Aldentec

1

bunu daha hızlı (dizi) yapılan bir Fonksiyon içinde yapılan bir Biti herkesin kodunu adapte ve katma parametreleri:

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 
.210
3

bu

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 
İlgili konular