2016-03-24 7 views
0

私はテーブルからのデータのみの検証をコピーしたいと呼ばれるTable1_1ワークシートテンプレートに(メイント。)テーブルに別のワークシートTEMPLATEにあります。私は利用可能なトピックを見てきましたが、私が探しているものに非常に近いものはありません。コピーデータの検証は

問題の1つは、これらのシートのいずれかの表がシフトする可能性があるため、このマクロを作成する際に考慮する必要があります。

は、これまでのところ私が持っているものです:ワークシートTEMPLATE(。メイント)上Table1_1

  1. コピー最初の(そして唯一の行)。
  2. ワークシートのセルA3を見てテンプレートを取得し、それが属するテーブルを取得します。
  3. 手順2で見つかった表の最初の行を見つけます。
  4. 最初の行の表のすべての列のデータ検証を貼り付けます。
  5. テーブルのすべての行について手順3と4を繰り返します。

私がこれまで持っているコード:

Dim TotalSheets As Integer 
Dim p As Integer 
Dim iAnswer As VbMsgBoxResult 

' This Dim is supposed to be to add worksheets, for the process _ 
' of copying the data validations to the new sheets, to a skip _ 
' list. An array perhaps? Skip any sheets listed in this array? 
Dim DNCToShts As ? 

' The cell to get the table that it is apart of for copying from _ 
' the other worksheet, "TEMPLATE (Maint.)" 
Dim GetCellsTable_Copy As String 
' The cell to get the table that it is apart of for pasting onto _ 
' the other worksheets. 
Dim GetCellsTable_Paste As String 

' This is the cell to reference on "TEMPLATE (Maint.)" worksheet _ 
' to get the table name of, this will always be "Table1_1" 
GetCellsTable_Copy = "A3" 
' This is the cell to reference on each sheet to get the table name. 
GetCellsTable_Paste = "A3" 

With Aplication 
    .DisplayAlerts = False 
    .ScreenUpdating = False 
End With 

iAnswer = MsgBox("You are about to copy data validations! Do you _ 
want to proceed?", vbOKCancel + vbExclamation _ 
+ vbDefaultButton2 + vbMsgBoxSetForeground + vbApplicationModal, _ 
"Copying Data Valadations") 

' Instead of copying the whole table I just need to copy the first row _ 
' of data, intending to copy just the data validations portion. 
Range("Table1_1").Copy 

If iAnswer = vbYes Then 
    p = 1 To Sheets.Count 
     If UCase$(Sheets(p).Name) <> DNCToShts 
     StoreTableName = Range(GetCellsTable_Paste).ListObject.Name 

私は私が私のエクセルVBAモジュールのそれぞれに達成することを目指しています何示す図を作成しました。これはすべての詳細を含まなくてもよいと私はパート1にのみを働いている点に注意してください:。 Diagram showing the sequence of sub usage

+2

Private関数であるべき私はすでに蓄積されているコードを追加した@TheGuyThatDoesntKnowMuch参照 –

+0

のためにあなたのコードの一部または全部を投稿してください。あなたが集めることができるものがあるのか​​、それ以上説明する必要がありますか? –

+0

私は基本的に上に貼り付けられている以外のコードはほとんど書かれていません。 : -/ –

答えて

1

エクセルVBAオンラインヘルプは、あなたがこれを行っていることのために必要なすべてを持っています。 Validationオブジェクトメンバのヘルプページで十分です。

次のルーチンは、あるセルから別のセルへの検証をコピーします。ダブルループで(ターゲットの行と列に対して)呼び出すことができるはずです。あなたはそれをテストが終了したら、これはおそらく

Sub CopyValidation(ByRef rngSourceCell As Range, ByRef rngTargetCell As Range) 
    With rngTargetCell.Validation 
     .Delete 
     .Add Type:=rngSourceCell.Validation.Type, _ 
      AlertStyle:=rngSourceCell.Validation.AlertStyle, _ 
      Operator:=rngSourceCell.Validation.Operator, Formula1:=rngSourceCell.Validation.Formula1, Formula2:=rngSourceCell.Validation.Formula2 
     .ErrorMessage = rngSourceCell.Validation.ErrorMessage 
     .ErrorTitle = rngSourceCell.Validation.ErrorTitle 
     .IgnoreBlank = rngSourceCell.Validation.IgnoreBlank 
     .IMEMode = rngSourceCell.Validation.IMEMode 
     .InCellDropdown = rngSourceCell.Validation.InCellDropdown 
     .InputMessage = rngSourceCell.Validation.InputMessage 
     .InputTitle = rngSourceCell.Validation.InputTitle 
     .ShowError = rngSourceCell.Validation.ShowError 
     .ShowInput = rngSourceCell.Validation.ShowInput 
    End With 
End Sub 
+0

私はこのコードをいくつかの方法で統合することができるかどうかを見てみましょう。これは有望です。 FYIはい、私はそれを独自のSub(Sub Copy_Data_Validations())として実行しています。 –

+0

あなたは "これはおそらく自分のプライベートな機能でなければならない"と述べましたか? "...プライベート関数"の代わりに? –

+1

私は "プライベートサブ"と言ったはずです。 「機能」は間違った言葉でした。これはすでにSubとして書かれています。私が言ったのは、デバッグウィンドウを使ってテストするのと同じように使えるということでした。あなたがそれでOKなら、それの前にプライベート修飾子を追加することができます。いずれにしても大したことではありません。 (私はデフォルトですべてをプライベートにする傾向があり、パブリックにする必要があるだけをパブリックにする傾向があります)。 – MikeC