マクロ作成方法16(自動記録・ファイル操作)
自動記録マクロで別のファイルを開いて元のファイルの指定セルにコピーして見ました。
「No.4予測パターン抽出.xlsm」のファイル上でNUMBERS 関 連フォルダーにある「n4プロパティ分析.xlsm」ファイルを開いてコピーしています。
手入力でこのマクロを作るのは非常に面倒ですね。普段ファイル操作しているのを自動記録で作成して行くのが良いですね。
Sub 間隔コピー()
ChDir "C:\Users\km\Desktop\NUMBERS 関 連"
Workbooks.Open Filename:="C:\Users\km\Desktop\NUMBERS 関 連\n4プロパティ分析.xlsm"
Windows("n4プロパティ分析.xlsm").Activate
Sheets("千百分析").Select
Range("K1:DF83").Select
Selection.Copy
Windows("No.4予測パターン抽出.xlsm").Activate
Sheets("間隔").Select
Range("B3").Select
ActiveSheet.Paste
End Sub
すでに別のファイルを開いておいて、今のファイルにコピーします。
別のファイルが閉じていた場合、エラーになります。
エラーにさせたくない時はマクロ間隔コピーのようにすれば良いでしょう。
Sub 最後当選へコピー()
'占星術コピイ含む
'
' LOTO6から最後の当選にコピーする。
gyou = Windows("LOTO6SlJ.xlsm").ActiveCell.Row
If Cells(gyou, 2) <> "" And Cells(gyou, 4) <> "" Then End
Windows("LOTO6.xlsm").Activate
Sheets("表 (2)").Select
Range(Cells(gyou - 1, 1), Cells(gyou - 1, 52)).Select
Selection.Copy
Windows("LOTO6SlJ.xlsm").Activate
Sheets("最後当選").Select
Cells(gyou, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Call 飛び記入_6
Range("BA3").Select
Selection.Copy
Cells(gyou, 53).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Call copiii
'占星術コピイ
Sheets("最後当選").Select
Cells(gyou, 3).Select
End Sub
Sub 飛び記入_6() '記入する行をクリックした後マクロ実行する。
retu = ActiveCell.Column
gyou = ActiveCell.Row
For i = 0 To 42
If Cells(gyou - 1, 10 + i) = "●" Or Cells(gyou - 1, 10 + i) = "○" Then
If Cells(gyou, 10 + i) = "" Then Cells(gyou, 10 + i) = 1
Else
If Cells(gyou, 10 + i) = "" Then Cells(gyou, 10 + i) = Cells(gyou - 1, 10 + i) + 1
End If
Next i
End Sub
Sub copiii() '占星術コピイ
Windows("LOTO6.xlsm").Activate
Sheets("元データ").Select
Range("DF4:DQ50").Select
Selection.Copy
Windows("LOTO6SlJ.xlsm").Activate
Sheets("占星術").Select
Range("C9").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("C9:N51").Select
Selection.FormatConditions.AddAboveAverage
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).AboveBelow = xlAboveAverage
With Selection.FormatConditions(1).Font
.Color = -16752384
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13561798
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.AddAboveAverage
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).AboveBelow = xlBelowAverage
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
ActiveWindow.SmallScroll Down:=-12
Range("B2").Select
End Sub