2017-10-19 6 views
1

現在、私は、より短いバージョンの大量のセルの単語を置き換えようとしています。私は単語の辞書を短くし、1つ以上の単語を短縮する必要があるセルの列を持っています。Excel VBAのデータベースに基づいて単語を短くする

私はVBAにとって非常に新しく、これについてどうやって行くのか分かりません。私は検索してみたが、それは単語の文書のテキストを変更することになりますが、少なくとも私の検索語ではExcelからExcelを抜き出すことはありません。

I思想のここに画像を追加して、短くするために、テキストが列Aにあり、短くすることができる単語が列Cにあり、短縮バージョンの列にあるがD.

Sample

+0

、それを行うだろうVBAで置き換えます。検索機能。このページには、vbaが値の範囲を検索し、そのセルに新しい値を割り当てる例があります。https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-find -method-excel – TPhe

答えて

0

ここでフルサブバージョンは、私は見てみるお勧めしますそれはあなた

Sub ReplaceViaList() 
Dim ws As Worksheet 
Dim repRng As Range 
Dim x As Long, lastRow As Long 
Dim repCol As Long, oldCol As Long, newCol As Long 
Dim oldStr As String, newStr As String 

'screenupdating/calc 
Application.Calculation = xlCalculationManual 
Application.ScreenUpdating = False 

'define worksheet 
Set ws = ActiveSheet 

'define columns to work with 
repCol = 1 'col A 
oldCol = 3 'col C 
newCol = 4 'col D 

'find last row of replacement terms 
lastRow = ws.Cells(ws.Rows.Count, repCol).End(xlUp).Row 

'set range of items to be replaced 
Set repRng = ws.Range(_ 
    ws.Cells(2, repCol), _ 
    ws.Cells(lastRow, repCol) _ 
    ) 

'loop through cells in replacement terms 
For x = 2 To ws.Cells(ws.Rows.Count, oldCol).End(xlUp).Row 

    'define replacement terms 
    oldStr = ws.Cells(x, oldCol).Value 
    newStr = ws.Cells(x, newCol).Value 

    'replace 
    repRng.Replace What:=oldStr, Replacement:=newStr 

Next x 

'screenupdating/calc 
Application.Calculation = xlCalculationAutomatic 
Application.ScreenUpdating = True 

End Sub 
+0

これは完全に機能しました!最初の試みにも取り組みました。コメントをありがとう、それは私が起こっていることをよりよく理解し、それから学ぶのに役立ちます! – ard

+0

お手伝いします!あなたが答えに満足しているなら、同じ問題を持つ他の人がそれを見つけるのを助けるためにそれを「受け入れる」ことを検討してください:「答えが「受け入れられる」とはどういう意味ですか?」(https://stackoverflow.com/ヘルプ/受け入れ - 回答) –

0

このUDFを使用できます。

Function SubstituteMultiple(text As String, old_text As Range, new_text As Range) 
Dim i As Single 
For i = 1 To old_text.Cells.Count 
Result = Replace(LCase(text), LCase(old_text.Cells(i)), LCase(new_text.Cells(i))) 
text = Result 
Next i 
SubstituteMultiple = Result 
End Function 

このコードは通常のモジュールに入れてください。この式=SubstituteMultiple(A2,$C$2:$C$11,$D$2:$D$11)をセルB2に書き込み、下にドラッグします。

enter image description here

0

のために良い作品ならば、おそらく簡単な

Sub test() 
    Dim searchval As Variant 
    Dim replaceval As Variant 

    searchval = Range("C1:C10") 
    replaceval = Range("D1:D10") 

    For i = 1 To 10 
     Columns("A:A").Replace What:=searchval(i, 1), Replacement:=replaceval(i, 1), LookAt:=xlPart 
    Next i 
End Sub 
関連する問題