สอบถามต่อครับ กรณีที่เราต้องการจะลบข้อมูลกับชีทอื่น ๆ ที่มีโครงสร้างแบบเดียวกัน ประมาณ 10-15 ชีท
Code ที่เขียนจะต้อง With Worksheets .................................End With ไปจนครบทุกชีทใช่หรือไม่ครับ
หรือสามารถย่อให้สั้นได้กว่านี้
Code: Select all
Sub clsScore()
Dim lastRow As Long
Dim i As Long, r As Range
With Worksheets("thai")
lastRow = .Cells(.Rows.Count, 44).End(xlUp).Row
lastRow = .Cells(.Rows.Count, 17).End(xlUp).Row
For i = 6 To lastRow
If .Cells(i, 2) = "" Then
.Cells(i, 6).Resize(, 14).ClearContents
.Cells(i, 21).Resize(, 2).ClearContents
.Cells(i, 26).Resize(, 14).ClearContents
.Cells(i, 41).Resize(, 2).ClearContents
End If
Next i
End With
With Worksheets("Eng")
lastRow = .Cells(.Rows.Count, 44).End(xlUp).Row
lastRow = .Cells(.Rows.Count, 17).End(xlUp).Row
For i = 6 To lastRow
If .Cells(i, 2) = "" Then
.Cells(i, 6).Resize(, 14).ClearContents
.Cells(i, 21).Resize(, 2).ClearContents
.Cells(i, 26).Resize(, 14).ClearContents
.Cells(i, 41).Resize(, 2).ClearContents
End If
Next i
End With
With Worksheets("pysical")
' With Worksheets.Sheet3
lastRow = .Cells(.Rows.Count, 44).End(xlUp).Row
lastRow = .Cells(.Rows.Count, 17).End(xlUp).Row
For i = 6 To lastRow
If .Cells(i, 2) = "" Then
.Cells(i, 6).Resize(, 14).ClearContents
.Cells(i, 21).Resize(, 2).ClearContents
.Cells(i, 26).Resize(, 14).ClearContents
.Cells(i, 41).Resize(, 2).ClearContents
End If
Next i
End With
With Worksheets("sci")
' With Worksheets.Sheet3
lastRow = .Cells(.Rows.Count, 44).End(xlUp).Row
lastRow = .Cells(.Rows.Count, 17).End(xlUp).Row
For i = 6 To lastRow
If .Cells(i, 2) = "" Then
.Cells(i, 6).Resize(, 14).ClearContents
.Cells(i, 21).Resize(, 2).ClearContents
.Cells(i, 26).Resize(, 14).ClearContents
.Cells(i, 41).Resize(, 2).ClearContents
End If
Next i
End With
End Sub
You do not have the required permissions to view the files attached to this post.