2016-12-19 3 views
0

大丈夫私はVBA /マクロを今日使い始めていて、私の進歩はかなり満足しています:)しかし、タブを見て、マッチさせ、次に掛け合わせて、アクティブなセルを置き換えてください。

救済措置を探していない私は将来このことを理解したいと思います。その後、私は、 "通貨"(リフレッシュウェブデータ)と呼ばれる通貨CONVタブを持って data tab

UPDATED CURRNのTAB :私の仕事は本当に "引用ツール" と呼ばれる

データタブ....これらを使用することができます: currencies tab

私がやりたいこと:通貨のデータタブを検索し、 "CNY"または "HKD"または別の通貨を探します。それが見つかったら、対応する "MSR"列セルに移動し、その値を右カーレシ変換に対応する "通貨"タブのセルで掛けて、そのセルに結果をデータタブに入れます。

私はこれを約5時間かけてスレッド間で異なるコードを一緒に披露しています。私は私が必要なもののためにあまりにも基本的に見えてきたもの:

は、私が実際には異なる検索と置換を使用して、ブック全体でマクロを実行するために管理しますが、これはあるUSER

Sub CurrencyConvTwo() 

Dim cell As Range, currRng As Range, currCell As Range 
With Worksheets("Currencies") '<--| reference "Currencies" sheet 
    Set currRng = .Range("A3", .Cells(.Rows.Count, 1).End(xlUp)) '<--| set the range with all currencies acronyms 
End With 

With Worksheets("Quotation Tool") '<--| reference "Quotation Tool" sheet 
    For Each cell In .Range("L3", .Cells(.Rows.Count, "L").End(xlUp)) '<--| loop through its column L ("Currency") cells from row 3 down to last not empty one 
     Set currCell = currRng.Find(what:=cell.Value, LookIn:=xlValues, lookat:=xlWhole) '<--| try finding current currency in "Currencies" sheet currencies range 
     If Not currCell Is Nothing Then cell.Offset(, 3) = cell.Offset(, 3) * currCell.Offset(, 3) '<--| if found, substitute current cell three columns offset to its current value times "Currencies" sheet found currency cell 2 columns offset 
    Next cell 
End With 

End Subの

からコードを更新しました私を困惑させる。あなたの考えは高く評価されています!

+0

CNYは私がちょうどペーストをコピーすると考えましたbecasue私はそこに持っている唯一の通貨であります正しいコーディングを見つけたら通貨を変更してください – IFianTHENdisplayname

+2

いつでもあなたの質問を編集できます。手順を記録することができ、Excelが使用するVBAコマンドのコマンドが表示されます。 Alt T、M、Rを繰り返して録音を停止します。 VBAエディタで記録されたコードを探します。 –

+0

また、['.Select' /' .Activate'の使用を避けてください。](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros) 。また、 'Rng = .Range(...')を使って 'Rng'を品質化する必要があります。これは' Vlookup'または 'Index/Match'で行うこともできます。 VBAソリューション? – BruceWayne

答えて

0

まず第一に、あなたがする必要があります。

  • のいずれか、それに対応する頭字語(例えばにすべての「通貨」シートの列Aの通貨名の文字列を変更:「CNY」に変更し、「中国人民元Renmimbi」.. 。)

  • またはその対応する名前(にすべての "引用ツール" シートの列L通貨の頭文字を変更する例:変更 "CNY" を "中国人民元Renmimbi"、...)

私は、前者が

が好ましいであろう。そして、あなたが1(コメント)は、次のようなコードを使用することができますね。

Option Explicit 

Sub CurrencyConv() 
    Dim cell As Range, currRng As Range, currCell As Range 

    With Worksheets("Currencies") '<--| reference "Currencies" sheet 
     Set currRng = .Range("A3", .Cells(.Rows.count, 1).End(xlUp)) '<--| set the range with all currencies acronyms 
    End With 

    With Worksheets("Quotation Tool") '<--| reference "Quotation Tool" sheet 
     For Each cell In .Range("L3", .Cells(.Rows.count, "L").End(xlUp)) '<--| loop through its column L ("Currency") cells from row 3 down to last not empty one 
      Set currCell = currRng.Find(what:=cell.Value, LookIn:=xlValues, lookat:=xlWhole) '<--| try finding current currency in "Currencies" sheet currencies range 
      If Not currCell Is Nothing Then cell.Offset(, 3) = cell.Offset(, 3) * currCell.Offset(, 2) '<--| if found, substitute current cell three columns offset to its current value times "Currencies" sheet found currency cell 2 columns offset 
     Next cell 
    End With 
End Sub 
+0

考えてくれてありがとう!私はあなたが言ったように、私が見つけた略語のリストに列Aとインデックスマッチを設定しました。私はあなたのコードを使用するとき、私はエラーを取得しないでも何も起こりません。これはちょうど私がここで考えていると私はこれについて多くを知っていないが、略語の "curencies"で一致するものを探すとき。セルが実際に数式であり、省略形が表示されるだけで問題はありませんか? – IFianTHENdisplayname

+0

ここには通貨の省略形があります。 – IFianTHENdisplayname

+0

あなたのスクリーンショットを実際のデータ構造に更新してください – user3598756

関連する問題