1

現在、列名をExcelの変数にマッピングしてから、数式の変数を新しい行に使用しています。例を次に示します。

Dim posType as String

Cells.Find(What:="PositionType", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=False).Activate


posType = ActiveCell.EntireColumn.Address(False, False)
posType = Left(posType, InStr(1, posType, ":") - 1)


Sheets("sheet1").Range("A1").Select

ActiveCell.End(xlToRight).Select

ActiveCell.Offset(0, 1).Select
Selection.FormulaR1C1 = "PTH Size"

 ' PTH SIZE
Cells.Find(What:="PTH SIZE", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=False).Activate
    ActiveCell.Offset(1, 0).Select

Selection.Formula = _
  "=IF(" & posType & "2=""PTH""," & settlementDateQuantity & "2,0)"

pthSize = ActiveCell.EntireColumn.Address(False, False)
pthSize = Left(pthSize, InStr(1, pthSize, ":") - 1)
r = ActiveCell.Row

With Worksheets("sheet1").Range(pthSize & r)
    .AutoFill Destination:=Range(pthSize & r & ":" & pthSize & lastrow&)
End With

インポートするファイルは、列の順序で日々変更される可能性がありますが、同じ名前を使用しています。現在、findメソッドを使用して列を取得し、文字を文字列に保存して、数式で参照を使用しています。 100列の検索とマッピングを使用するプロセスはかなり遅いです...

私はこれを行うためのより良い方法を考え出そうとしていますが、もっと速く何かを考えることはできません、誰かがこれを行うためのおそらくより速い方法を提案することによって私を助けることができますか?

プロジェクトをEXCELDNAに移行することも検討していますが、マクロの実行がどれだけ速くなるかを誰かが知っていますか?

ありがとう

4

1 に答える 1

1

割り当てを行うだけでなく、ワークブックを選択して移動していると、プログラムの速度が大幅に低下します!!!

私はあなたを正しい方向に動かすためにいくつかの変更を加えました - これを試してみてください: (注: 迅速で汚いので、セル参照でいくつかの間違いを犯したかもしれませんが、少なくともより良い方向にあなたを動かすはずです. )

  Dim posType As String
  Dim SelectedCell As Range

  Set SelectedCell = Cells.Find(What:="PositionType", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
      :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
      False, SearchFormat:=False)

  posType = Mid(SelectedCell.Address, 2, InStr(2, SelectedCell.Address, "$") - 2)

  Set SelectedCell = Sheets("sheet1").Range("A1").End(xlToRight).Offset(0, 1)
  SelectedCell.Value = "PTH Size"

   ' PTH SIZE
  Set SelectedCell = Cells.Find(What:="PTH SIZE", After:=SelectedCell, LookIn:=xlFormulas, _
  LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
      False, SearchFormat:=False).Offset(1, 0)

  SelectedCell.Formula = "=IF(" & posType & "2=""PTH""," & settlementDateQuantity & "2,0)"


  pthSize = Mid(SelectedCell.Address, 2, InStr(2, SelectedCell.Address, "$") - 2)
  r = SelectedCell.Row

  Worksheets("sheet1").Range(pthSize & r).AutoFill Destination:=Range(pthSize & r & ":" & pthSize & lastrow&)

繰り返しますが、これはまだ大幅に効率化できることに注意してください。しかし、これは物事を行うためのはるかに効率的な方法です...

于 2012-11-28T17:17:44.580 に答える