숫자, 전체 정지 및 밑줄이 혼합 된 일부 셀에 많은 양의 데이터가 있습니다. 그러나, 숫자가 들어있는 셀을 삭제하는 매크로를 만들고 싶습니다. 왼쪽의 셀에만 알파벳의 문자가 포함되어 있습니다. 아래에 현재 코드가 있지만 제대로 작동하지 않습니다. 어떻게 수정해야합니까?특정 수의 값을 기반으로 셀을 삭제하려면 어떻게합니까?
Sub Sample()
Dim ws As Worksheet
Dim strSearch As String
Dim Lrow As Long
strSearch = "."
strSearch = "0"
strSearch = "1"
strSearch = "2"
strSearch = "3"
strSearch = "4"
strSearch = "5"
strSearch = "6"
strSearch = "7"
strSearch = "8"
strSearch = "9"
strSearch = "."
Set ws = Sheets("Sheet1")
With ws
Lrow = .Range("A" & .Rows.Count).End(xlUp).Row
'~~> Remove any filters
.AutoFilterMode = False
'~~> Filter, offset(to exclude headers) and delete visible rows
With .Range("A1:A" & Lrow)
.AutoFilter Field:=1, Criteria1:="=*" & strSearch & "*"
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
'~~> Remove any filters
.AutoFilterMode = False
End With
End Sub
는 또한 제대로 작동하지 않는 코드의이 비트를 가지고있다. 두 가지 중 어느 것을 사용해야합니까? 어떻게 수정합니까? 또한 어느 것을 사용해야합니까?
Sub Test()
Dim cell As Range
For Each cell In Selection
If InStr(1, cell, "1", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
For Each cell In Selection
If InStr(1, cell, "2", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
For Each cell In Selection
If InStr(1, cell, "3", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
For Each cell In Selection
If InStr(1, cell, "4", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
For Each cell In Selection
If InStr(1, cell, "5", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
For Each cell In Selection
If InStr(1, cell, "6", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
For Each cell In Selection
If InStr(1, cell, "7", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
For Each cell In Selection
If InStr(1, cell, "8", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
For Each cell In Selection
If InStr(1, cell, "9", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
For Each cell In Selection
If InStr(1, cell, "0", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
For Each cell In Selection
If InStr(1, cell, ".", vbTextCompare) > 0 Then
cell.EntireRow.Delete
End If
Next
End Sub
'strSearch'에 대해 *** 배열 ***이 필요합니다. –
알파벳 문자 만 검색하는 좋은 질문이 있습니다 (http://stackoverflow.com/questions/29633517/how-can-i-check -if-a-string-only-letters)를 포함합니다. 리펙토링을 원할 경우 코드를 단순화 할 수 있습니다. – Joe
게리 - 죄송합니다, 저는이 경험이 많습니다. 그러나 배열에 대해 많은 언급을 들었습니다. 어디서 어떻게 통합 할 것인가? – Imperdiet