Có rất nhiều lựa chọn khác nhau ở đây:
Chỉ bằng cách thêm hôn mê trong chuỗi tìm kiếm sẽ được thay thế và sử dụng s1 = Trim(Replace(mystring, "site,", "",1,1)) 0 để loại bỏ không gian:adding the coma in the search string to be replaced and use s1 = Trim(Replace(mystring, "site,", "",1,1)) 0 to get rid of spaces :
s1 = Trim(Replace(mystring, "site,", ""))Chỉ định số thời gian bạn muốn chuỗi được thay thế (đầu tiên "1" là lần bắt đầu, lần thứ hai cho số lần thay thế)the number of time you want the string to be replaced (first "1" is the start, the second for the number of replacements)
s1 = Trim(Replace(mystring, "site,", "",1,1))Hoặc một cách khó/xấu, để phân tách chuỗi của bạn thành hai mảnh sau lần xuất hiện đầu tiên và sau đó tái tổ hợp để có được kết quả ...decompose your string in two pieces after the first occurence and then recombine to get result...
TempStart = Left(mystring, InStr(1, mystring, "site") + Len(mystring) + 1) TempEnd = Replace(mystring, TempStart, "") TempStart = Replace(TempStart, "site", "") mystring = CStr(TempStart & TempEnd)
##*## Với Sub GetPartialText()
Dim R As Long, X As Long
Dim Data As Variant, Result As Variant
Dim Answer As String, Words() As String
Answer = InputBox("What text did you want to search for?")
If Len(Trim(Answer)) Then
Data = Range("A1", Cells(Rows.Count, "A").End(xlUp))
ReDim Result(1 To UBound(Data), 1 To 2)
For R = 1 To UBound(Data)
Words = Split(Data(R, 1), ",")
For X = 0 To UBound(Words)
If InStr(1, Words(X), Answer, vbTextCompare) Then
Result(R, 2) = Result(R, 2) & "," & Words(X)
Else
Result(R, 1) = Result(R, 1) & "," & Words(X)
End If
Next
Result(R, 1) = Mid(Result(R, 1), 2)
Result(R, 2) = Mid(Result(R, 2), 2)
Next
Range("A1").Resize(UBound(Result), 2) = Result
End If
End Sub
#6 Với Function GetText(s As String) As String
Dim strInput As String, Spl As Variant, i As Long
strInput = InputBox("What text did you want to search for?")
If Len(strInput) Then
Spl = Split(Application.Trim(s), ",")
For i = LBound(Spl) To UBound(Spl)
If UCase(Left(Spl(i), Len(strInput))) <> UCase(strInput) Then Spl(i) = " "
Next i
GetText = Replace(Application.Trim(Join(Spl)), " ", ",")
End If
End Function ' #6
Cũng quyết định sử dụng kịch bản Krishnakumar, đó là người duy nhất làm việc với Get Go, và cũng không cần sửa đổi. Cảm ơn mọi người vì những câu trả lời tuyệt vời. Với Function GetText(s As String) As String
Dim strInput As String, Spl As Variant, i As Long
strInput = InputBox("What text did you want to search for?")
If Len(strInput) Then
Spl = Split(Application.Trim(s), ",")
For i = LBound(Spl) To UBound(Spl)
If UCase(Left(Spl(i), Len(strInput))) <> UCase(strInput) Then Spl(i) = " "
Next i
GetText = Replace(Application.Trim(Join(Spl)), " ", ",")
End If
End Function ' #6 Re: Xóa hoặc xóa một phần của văn bản ôand then delete the copied part from the original cell but leaving the rest of text in the source cell
unmodified.
=GetText(A2)
=GetText(A2)
.
- Cũng quyết định sử dụng kịch bản Krishnakumar, đó là người duy nhất làm việc với Get Go, và cũng không cần sửa đổi. Cảm ơn mọi người vì những câu trả lời tuyệt vời.
#7 Làm việc tốt trong bài kiểm tra của tôi.and then delete...." #6
- Re: Xóa hoặc xóa một phần của văn bản ô
Cũng quyết định sử dụng kịch bản Krishnakumar, đó là người duy nhất làm việc với Get Go, và cũng không cần sửa đổi. Cảm ơn mọi người vì những câu trả lời tuyệt vời. #7 Trân trọng Ingemar
- Làm thế nào về chỉnh sửa> thay thế
##*##
Thanks for looking and helping a fellow IT member.- #2
Re: Xóa một số dữ liệu khỏi ô nhưng không phải tất cả dữ liệu
Boriqua,
Đây là mã được sửa đổi khỏi việc xóa văn bản sau khi vận chuyển trở lại*
Deleting Text After Carriage Return*Public Function ConvertFunction(ByRef oldFormat As String) As String Dim x As Integer x = InStr(3,oldFormat, "##") If x > 0 Then ConvertFunction= Right(oldFormat,Len(oldFormat)- x + 1) Else ConvertFunction= "No ## characters found after position 2" End If End Function
Hiển thị nhiều hơn
... và có thể được sử dụng như một phần của tập lệnh hoặc trực tiếp từ bảng tính.
G.
*Tín dụng cho Krishnakumar
- #3
Re: Xóa một số dữ liệu khỏi ô nhưng không phải tất cả dữ liệu
Đây là mã được sửa đổi khỏi việc xóa văn bản sau khi vận chuyển trở lại*
Sub removeextra() Dim x As Integer For x = 2 To Sheets(1).Range("A63353").End(xlUp).Row Sheets(1).Range("A" & x).Replace What:="##NML##", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Sheets(1).Range("A" & x).Replace What:="##WRN##", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Next x End Sub
Hiển thị nhiều hơn
- ... và có thể được sử dụng như một phần của tập lệnh hoặc trực tiếp từ bảng tính.
Re: Xóa một số dữ liệu khỏi ô nhưng không phải tất cả dữ liệu
Hi,
G.
With Columns("A:A")
.Replace What:="##NML##=", Replacement:="##NML## "
.Replace What:="##NML##", Replacement:=""
.Replace What:="##WRN##=", Replacement:="##WRN## "
.Replace What:="##WRN##", Replacement:=""
End With
End Sub[/vba]*Tín dụng cho Krishnakumar
- #3
Re: Xóa một số dữ liệu khỏi ô nhưng không phải tất cả dữ liệu
Cho cái này một phát súng. Ngoại trừ vòng lặp tiếp theo, về cơ bản tôi đã ghi lại điều này, nhưng nó sẽ chỉ cho bạn đúng hướng hoặc ở mức tối thiểu cung cấp cho bạn một tùy chọn thay thế.Edit>Replace
#4
. #", Thay thế: =" ".replace What: =" ## WRN ## = ", Thay thế: =" ## WRN ## ".replace What: =" ## WRN ## ", Thay thế: =" "" Kết thúc với Sub [/VBA]
Hth
- #5
Làm thế nào về chỉnh sửa> thay thế
##*##
- Với
Làm thế nào về chỉnh sửa> thay thế
With Columns("A:A").Replace What:="##*##", Replacement:="'"
##*##
- Với
Làm thế nào về chỉnh sửa> thay thế
Sub test() Dim r As Range With CreateObject("vbscript.regexp") .Pattern = "##\D+##" For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp)) If .test(r.Value) Then txt = .Replace(r.Value, "") If Left(txt, 1) = "=" Then txt = "'" & txt r.Value = txt End If Next End With End Sub
Hiển thị nhiều hơn