엑셀 VBA 특정 cell의 값을 다른 cell에서 prefix로 가지고 있을 때 제거
excel vba while문, for문, if문, instr(문자열 포함 검사), split 예제
Sub 이름떼기()
Dim i As Long
Dim j As Long
Dim k As Long
Dim sfrName As String
Dim fieldName As String
Dim stringTmp() As String
i = 5
Do While IsEmpty(Cells(i, 3).Value) = False
sfrName = Cells(i, 3).Value & "_"
For j = 0 To 1
For k = 4 To 19
fieldName = Cells(i + j, k).Value
If InStr(fieldName, sfrName) Then
stringTmp = Split(fieldName, sfrName)
fieldName = stringTmp(1)
Cells(i + j, k).Value = fieldName
End If
Next
Next
i = 2 + i
Loop
End Sub
Sub 이름떼기()
Dim i As Long
Dim j As Long
Dim k As Long
Dim sfrName As String
Dim fieldName As String
Dim stringTmp() As String
i = 5
Do While IsEmpty(Cells(i, 3).Value) = False
sfrName = Cells(i, 3).Value & "_"
For j = 0 To 1
For k = 4 To 19
fieldName = Cells(i + j, k).Value
If InStr(fieldName, sfrName) Then
stringTmp = Split(fieldName, sfrName)
fieldName = stringTmp(1)
Cells(i + j, k).Value = fieldName
End If
Next
Next
i = 2 + i
Loop
End Sub
댓글
댓글 쓰기