EXCEL TOOLS
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
[code]
และปิดด้วย [/code]
ตัวอย่างเช่น [code]dim r as range[/code]
เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)Code: Select all
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
Code: Select all
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
Code: Select all
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
Code: Select all
If .Value = "407" Or .Value = "309" Then .EntireRow.Delete
Code: Select all
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
Code: Select all
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
Code: Select all
For i = lr To 2 Step -1
Code: Select all
If .Range("A" & i).Value = "14*" Or .Range("A" & i).Value = "17*" Then
Code: Select all
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