Excel'de tblFruits
10 sütunlu bir tablo var ve Fruit
sütununun Apple
içerdiği satırları silmek istiyorum. Bunu nasıl yapabilirim?Excel ListObject'te satırlar, VBA kullanarak ölçütlere göre nasıl silinir?
6
A
cevap
7
aşağıdaki alt eserleri:
Private Sub deleteTableRowsBasedOnCriteria(tbl As ListObject, columnName As String, criteria As String)
Dim x As Long, lastrow As Long, lr As ListRow
lastrow = tbl.ListRows.Count
For x = lastrow To 1 Step -1
Set lr = tbl.ListRows(x)
If Intersect(lr.Range, tbl.ListColumns(columnName).Range).Value = criteria Then
'lr.Range.Select
lr.Delete
End If
Next x
End Sub
alt böyle infaz edilebilir:
Dim tbl As ListObject
Set tbl = ThisWorkbook.Worksheets("Sheet1").ListObjects("tblFruits")
Call deleteTableRowsBasedOnCriteria(tbl, "Fruit", "Apple")
2
Eh, .listrows mülkiyet BİR liste satır veya TÜM liste satır ya sınırlıdır görünüyor . , Formülü gerekmeyebilir (ı ortadan kaldırmak istiyorum tüm satırları bana işaret edecek bir formülle bir sütun kurma
: Bunu aşmanın bulundu
kolay yolu ile yapıldı tercihen (söz konusu sütun üzerinde ListObject sıralama silinecek benim değer ListRows aralığının adresini alınıyor sıralama sonunda)
de olacağını, böyle yapmakla bu durumda)
I del olacak Son olarak, alınan menzili silme, hücreleri hareket ettirme. Bu kod belirli bir parça olarak
Sub Delete_LO_Rows
Const ctRemove as string = "Remove" 'value to be removed
Dim myLO as listobject, r as long
Dim N as integer 'number of the listcolumn with the formula
Set myLo = Sheet1.ListObjects("Table1") 'listobject goes here
With myLO
With .Sort
With .SortFields
.Clear
.Add Key:=.HeaderRowRange(myLO.ListColumns(N)), SortOn:= _
xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End With
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
On Error GoTo NoRemoveFound
r = Application.WorksheetFunction.Match(ctRemove, .ListColumns(.ListColumns.Count).DataBodyRange, 0)
Range(.parent.name & "!" & .DataBodyRange(r, 1).Address & ":" & .DataBodyRange(.ListRows.Count, .ListColumns.Count).Address).Delete xlShiftUp
'Added the .parent.name to make sure the address is on the correct sure, but it will fail if there are any spaces or characters on the sheet name that will make it need a pair of '.
'The error is just to skip these two lines in case the match returns an error. There's likely a better/cleaner way to do that.
NoRemoveFound:
End With
End sub
Umarım yardımcı olur ...
İlgili konular
- 1. excel vba daha hızlı satırlar arası
- 2. Excel VBA
- 3. excel-vba
- 4. Değeri, aralığa göre bulun Excel-VBA
- 5. Excel VBA
- 6. Mysql içinde INNER JOIN kullanarak iki tablodaki satırlar nasıl silinir?
- 7. Bellek eksikliği Excel VBA
- 8. Bir veri çerçevesindeki tüm satırlar nasıl silinir?
- 9. Dönüt yapısı alan değeri ölçütlere göre
- 10. VBA kullanarak Excel hücrelerinin arka plan rengini nasıl ayarlayabilirim?
- 11. Mongoose - ölçütlere göre alt belgeleri bulma
- 12. Oluşturma Kodu 128 Excel VBA kullanarak barkodlar
- 13. excel çalışma sayfamı VBA
- 14. VBA ile Word'deki hücre içeriği nasıl silinir?
- 15. erişim değeri Excel VBA
- 16. VBA Excel GetSaveAsFilename parametresi
- 17. excel tablosundan VBA
- 18. VBA Excel - Excel'de iki kalın hücre
- 19. Tablodaki hizalama vba excel
- 20. Excel VBA Colon
- 21. excel vba, bir aralıkta
- 22. OnClick in Excel VBA
- 23. Excel VBA Vurgula arama
- 24. Excel VBA, hücreden önceki değerlere göre boş hücreleri doldurmak için
- 25. Excel VBA kullanarak çalışma zamanında MS Access nasıl açılır?
- 26. Excel içinde VBA içinde tamamlandı
- 27. Excel: ClearContent koruyarak formüller Excel VBA
- 28. Excel tablosundan bir Kare Matris seçin (VBA)
- 29. Excel VBA Rnd Aslında Rastgele
- 30. Excel VBA akımı aya dönüş
yinelenen: http://stackoverflow.com/questions/7648655/how-to-delete- satırlar-in-excel tabanlı-on-ölçüt kullanılarak-vba –