snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub deleteRowswithSelectedText()
For Each Cell In Selection
If Cell.Value = "407" Then
Rows(Cell.Row).ClearContents
End If
Next
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
End Sub
Sub deleteRowswithSelectedText()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'We use the ActiveSheet but you can replace this with
'Sheets("MySheet")if you want
With ActiveSheet
'We select the sheet so we can change the window view
.Select
'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
'We check the values in the A column in this example
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
If .Value = "162" Then .EntireRow.Delete
'This will delete each row with the Value "ron"
'in Column A, case sensitive.
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
Sub deleteRowswithSelectedText()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
If .Value = "162" Then .EntireRow.Delete
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
Sub test()
Dim lr As Long, i As Integer
Application.ScreenUpdating = False
With Sheets("Sheet1")
lr = .Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 2 Step -1
If .Range("A" & i).Value = "309" Or .Range("A" & i).Value = "407" Then
.Range("A" & i).EntireRow.Delete
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
Sub test()
Dim lr As Long, i As Integer
Application.ScreenUpdating = False
With Sheets("Sheet1")
lr = .Range("A" & Rows.Count).End(xlUp).Row
[color=#FF0000]For i = lr To 2 Step -1[/color]
If .Range("A" & i).Value = "309" Or .Range("A" & i).Value = "407" Then
.Range("A" & i).EntireRow.Delete
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
Sub test1()
Dim lr As Long, i As Long
Application.ScreenUpdating = False
With Sheets("Sheet1")
lr = .Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 2 Step -1
If Left(.Range("A" & i).Value, 2) = "14" Or Left(.Range("A" & i).Value, 2) = "17" Then
.Range("A" & i).EntireRow.Delete
End If
Next i
End With
Application.ScreenUpdating = True
End Sub