Vai al contenuto principale

Come trovare e sostituire più valori contemporaneamente in Excel?

doc multiplo trova sostituisci 1

Come tutti sappiamo, possiamo utilizzare la funzione Trova e sostituisci per trovare più celle della stessa e sostituirle con un valore di cui hai bisogno. Ma a volte, è necessario applicare la sostituzione molti-a-molti contemporaneamente. Ad esempio, ho una serie di dati e ora voglio sostituire tutte le mele con le mele rosse, le arance con le arance verdi, le banane con le banane gialle e così via come mostrato nelle seguenti schermate, hai buone idee per risolvere questo compito in Eccellere?

Trova e sostituisci più valori contemporaneamente con il codice VBA


freccia blu freccia destra Trova e sostituisci più valori contemporaneamente con il codice VBA

Se sei stanco di trovare e sostituire i valori più e più volte, il seguente codice VBA può aiutarti a sostituire più valori con i testi necessari contemporaneamente.

1. Si prega di creare le condizioni che si desidera utilizzare che contengano i valori originali e i nuovi valori. Vedi screenshot:

doc multiplo trova sostituisci 2

2. Quindi tieni premuto il pulsante ALT + F11 chiavi per aprire il Finestra di Microsoft Visual Basic, Applications Edition.

3. Clic inserire > Modulie incolla il codice seguente nella finestra del modulo.

Codice VBA: trova e sostituisci più valori contemporaneamente

Sub MultiFindNReplace()
'Updateby Extendoffice
Dim Rng As Range
Dim InputRng As Range, ReplaceRng As Range
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Original Range ", xTitleId, InputRng.Address, Type:=8)
Set ReplaceRng = Application.InputBox("Replace Range :", xTitleId, Type:=8)
Application.ScreenUpdating = False
For Each Rng In ReplaceRng.Columns(1).Cells
    InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value
Next
Application.ScreenUpdating = True
End Sub

4. Quindi premere F5 chiave per eseguire questo codice, nella finestra del messaggio spuntata, specificare l'intervallo di dati in cui si desidera sostituire i valori con nuovi valori.

doc multiplo trova sostituisci 3

5. Clic OKe viene visualizzata un'altra finestra di messaggio per ricordarti di selezionare i criteri creati nel passaggio 1. Vedi screenshot:

doc multiplo trova sostituisci 4

6. Quindi fare clic OK, tutti i valori specifici sono stati sostituiti con i nuovi valori di cui hai bisogno immediatamente.

doc multiplo trova sostituisci 5


Articoli correlati:

Come trovare e sostituire un testo specifico nelle caselle di testo?

Come trovare e sostituire il testo nei titoli dei grafici in Excel?

Come trovare e sostituire il testo all'interno dei commenti in Excel?

Come modificare più percorsi di collegamento ipertestuale contemporaneamente in Excel?

 

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!

 

Comments (136)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Sub MultiFindNReplace()
'Actualizar 20140722
Dim Rng As Range
Dim InputRng As Range, ReplaceRng As Range
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Original Range", xTitleId, InputRng.Address, Type:=8)
Set ReplaceRng = Application.InputBox("Replace Range:", xTitleId, Type:=8)
Application.ScreenUpdating = False
For Each Rng In ReplaceRng.Columns(1).Cells
InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value, LookAt:=xlWhole
Next
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
amigo este post tiene como 8 años pero funciona, que buen aporte para los que no sabemos excel
This comment was minimized by the moderator on the site
Dei uma modificada no código, e no meu caso, as referências de células são estáticas:

Sub MetodoReplace()

Dim rng As Range, xTitleId As String
Dim inputRng As Range, replaceRng As Range

Application.ScreenUpdating = False

xTitleId = "Metodo Replace"
Set inputRng = Range("A1").CurrentRegion.Offset(1, 0)
Set inputRng = Application.InputBox("Original range:", xTitleId, inputRng.Range("A1").CurrentRegion.Address, _
Type:=8)
Set replaceRng = Application.InputBox("Reaplicar Range:", xTitleId, inputRng.Range("C2").CurrentRegion.Address, _
Type:=8)

For Each rng In replaceRng.Columns(1).Cells
inputRng.Replace What:=rng.Value, Replacement:=rng.Offset(0, 1).Value
Next

Application.ScreenUpdating = True
This comment was minimized by the moderator on the site
Благодарю за экономию моего времени! Успехов!
This comment was minimized by the moderator on the site
Hallo,

ich würde gerne den Text in den Tabellen des Jahresabschlusses automatisch von Deutsch ins Englische übersetzen.
Dazu habe ich eine Excel Arbeitsmappe in welchem die Übersetzungstabelle "Ersatz" enthalten ist und in den folgenden Tabellenblättern die verschiedenen Tabellen wie zb. die Konzernbilanz, GuV, Geldflussrechnung etc.
Dazu habe ich ihren Code versucht zu transformieren. Die Übersetzung erfolgt im Grunde auch, aber zb. Vermögen - Assets; Finanzielle Vermögenswerte - Financial Assets wird nicht korrekt übersetzt, die Finanziellen Vermögenswerte übersetzt es als "Financial Assetswerte". auch in thousands EUR wir offensichtlich mit USA kombiniert.

Hier der Code (meine VBA Kenntnisse sind nur sehr minimalistisch):
Sub MultiFindNReplace2()
'Updateby Alex
Dim Rng As Range
Dim InputRng As Range, ReplaceRng As Range
Dim Ws As Worksheet

Set Ws = Worksheets("Konzernbilanz")
Set Ws = Worksheets("Konzerngesamtergebnis")
Set Ws = Worksheets("Konzerneigenkapitalspiegel")
Set Ws = Worksheets("Konzerngeldfluss")
Set InputRng = Ws.Range("D:Z")

Set Ws = Worksheets("Ersatz")
Set ReplaceRng = Ws.Range("A:B")

Application.ScreenUpdating = False
For Each Rng In ReplaceRng.Columns(1).Cells
InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value
Next
Application.ScreenUpdating = True
End Sub

Evtl. haben sie auch eine Idee wie ich dem Programm sagen kann, dass alle Tabellenblätter übersetzt werden müssen, außer natürlich die Tabelle "Ersatz".

Vielen Dank

Sg
Alex
This comment was minimized by the moderator on the site
Buenas !

Sabe alguien si se puede ejecutar en varias hojas de un mismo excel simultaneamente ?


Muchas gracias !!!
This comment was minimized by the moderator on the site
Hello, Roman,
If you want to find and replace in multiple worksheets, the following VBA code may do you a favor.
Note: Sheet1, Sheet2 are the sheet names that you want to find and replace values from, please separate the sheet names by comma; A1:AA100is the original data range you want to replace the specific values.
Sub MultiFindNReplace()
'Updateby Extendoffice
Dim xArrSh()
Dim Rng As Range
Dim xStrRgAddress As String
Dim InputRng As Range, ReplaceRng As Range
Dim xCells As Range
Dim xWSHs As Sheets
Dim xWSh As Worksheet
xArrSh = Array("Sheet1", "Sheet2") 'The sheet names, please separate the sheet names by comma
xStrRgAddress = "A1:AA100" 'the original data range you want to replace
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set ReplaceRng = Application.InputBox("Replace Range :", xTitleId, Type:=8)
If ReplaceRng Is Nothing Then Exit Sub
Set xWSHs = Application.ActiveWorkbook.Worksheets
Application.ScreenUpdating = False
For xI = 0 To UBound(xArrSh)
Set xWSh = xWSHs(xArrSh(xI))
Set xCells = xWSh.Range(xStrRgAddress)
For Each Rng In ReplaceRng.Columns(1).Cells
    xCells.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value
Next
Next
Application.ScreenUpdating = True
End Sub


After inserting the code, run this code, and a prompt box will pop up, select the original data and new data you want to find and replace with. see screenshot:
https://www.extendoffice.com/images/stories/comments/comment-skyyang/doc-multiple-find-replace.png

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Olá amigos o código é interessante porem não consegui que funciona-se ficarei muito grato se alguém se dispor a ajuda tenho certeza que será útil para outras pessoas.
exemplo:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 25
tenho esses números em uma linha
2 4 5 9 10 11 12 14 15 17 18 20 21 22 25
2 3 4 5 6 8 9 10 11 16 17 18 20 22 23
2 3 4 5 6 7 8 10 11 12 14 15 16 21 22
2 3 4 7 8 10 11 13 14 15 17 20 22 23 25
2 3 8 9 10 11 12 13 14 16 18 20 21 23 25
2 5 6 7 8 9 11 12 13 15 17 18 21 22 23
3 4 6 7 9 11 12 14 15 16 17 18 20 23 25
2 3 4 6 7 8 9 13 14 16 17 18 21 22 25
3 5 6 10 13 14 15 16 17 18 20 21 22 23 25
2 4 5 6 7 8 9 10 12 13 15 16 17 20 25
e esse grupo em outras porem preciso localizar e substituir e criar vinculo das células com seus respectivos números
exemplo: 02 com 02, 03 com 03, 04 com 04
att: Rosemar
This comment was minimized by the moderator on the site
Hello friend,

Sorry to hear that. Your situation is different from the example in the article. Our VBA code can only replace the original values with the value you define. It can't create a link between the cells with their respective numbers. Sorry for that. Have a nice day.

Sincerely,
Mandy
This comment was minimized by the moderator on the site
Bonjour,
merci pour votre support. Cela répond presque à mon besoin.Par contre, comment faire quand la même valeur se trouve dans "Origine value" et "Replacing value" car la valeur modifiée redevient la valeur d'origine ?Exemple : Origine value    ->    Replacing value
 
13h - 21h  ->  5h - 13h
8h - 16h   -> 10h - 18h
10h - 18h  ->  8h - 16h

Merci par avance pour votre aide
This comment was minimized by the moderator on the site
hello can we change also color ?  ex : i wanna change apple to red apple with the red filled cell
This comment was minimized by the moderator on the site
Is this method can be use if between sentence in a cell?e.g I want to change numbers between the line : abcdefghi 12345 jklmnopqrstu >>> abcdefghi 67891 jklmnopqrstu

if no is there any other method can be use? Please help. Thank you!
This comment was minimized by the moderator on the site
Hello, qill,The code in this article can finish your problem, please try, thank you!

There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations