VBA는 별도의 목록에서 여러 문자열을 바꿉니다.
문제
STRINGS를 교체해야 하는데 지금까지는 단어만 교체했습니다.코드는 설명 열을 통과하며 목록의 모든 시퀀스를 대체해야 합니다.아이디어는 약어를 사용하는 것입니다(새로운 가치) 완전한 단어보다는 (오래된 가치).
인접한 (공백 없음) 단어, 문자 등이 있을 때마다 코드가 실패합니다.뭐가 잘못 되었 니?감사합니다!!!
Sub ReplaceWords_BUT_Need_ToReplaceStrings()
Application.ScreenUpdating = False
'This macro works with separated words only. Eliminate hyphens etc before applying this macro.
Dim r As Range, A As Range
Dim s1 As Worksheet, s2 As Worksheet, LastRow As Integer, v As String, j As Integer,
oldv As String, newv As String
LastRow = Cells(Rows.count, "A").End(xlUp).row
Set s1 = Sheets("JE_data")
Set s2 = Sheets("ListToReplace")
Set A = s1.Range("J:J").Cells.SpecialCells(xlCellTypeConstants)
For Each r In A
v = r.Value
For j = 2 To LastRow
oldv = s2.Cells(j, 1).text
newv = s2.Cells(j, 2).text
'사용한 함수 바꾸기는 대소문자를 구분합니다.'모든 송장 단어가 대문자로 시작합니까?'그렇지 않다면 대신 v = 바꾸기(v, oldv, newv, 1, -1, vbTextCompare) 함수를 사용하세요.좋아요.
v = Replace(v, oldv, newv, 1, -1, vbTextCompare)
'v = Replace(v, oldv, newv)
Next j
r.Value = Trim(v)
Next r
Application.ScreenUpdating = True
End Sub
예:
목록바꾸기
Left column (old) Right column (new)
----------------------------------------
Invoice inv
Salary sy
Credit cr
JE_데이터
cr Note
cr note
INV/2712/14RF/0229/14
Invoice 1078 10
TECHNOQ01SI 2014 03288
(편집자 주: 예시는 댓글에 써놨기 때문에 맞는지는 모르겠네요)
Credit
로 대체되었습니다 cr
그리고 Invoice
로 대체될 것으로 예상됐다. inv
하지만 그렇지 않았어
해결책
사용한 함수를 바꾸십시오. 대소문자를 구분합니다.모든 청구서 단어가 대문자로 시작합니까?그렇지 않다면 다음을 사용하십시오
v = Replace(v, oldv, newv, 1, -1, vbTextCompare)
대신 기능을 수행합니다.
제휴하지 않습니다 StackOverflow