このマクロは、一度に1つのセルに適用する(または複数の行にドラッグすると、一番左上のセルの行に作用します)場合に機能します。ユーザーが一括して行を変更できるように、選択したすべてのセルの行に変更を適用するマクロを取得するために、それをさらに微調整する方法はありますか?1つのセルから複数のセルへのExcel VBAマクロ
最後に8行に1つの行を分割するマクロを記録しましたcolumns J:Q
ロジックは、選択されたセル(マージ対象のセルの下に存在する)の上に7行挿入し、 columns A:I
のためのオリジナルの既存の行と行は、これは私にA:I
のための1つのセルと、私はこのコードのより多くの意味を理解し、ずっとそれを作るためにいくつかの調整を行った
*See macro below
Sub splitrowsandmerge()
'
' splitrowsandmerge Macro
' add 7 rows and merge 8 rows for first 9 columns
'
' Keyboard Shortcut: Ctrl+Shift+E
'
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
ActiveCell.Offset(-1, 0).Range("A1:A8").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.Offset(0, 1).Range("A1:A8").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.Offset(0, 1).Range("A1:A8").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.Offset(0, 1).Range("A1:A8").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.Offset(0, 1).Range("A1:A8").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.Offset(0, 1).Range("A1:A8").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlLTR
.MergeCells = False
End With
Selection.Merge
ActiveCell.Offset(0, 1).Range("A1:A8").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.Offset(0, 1).Range("A1:A8").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.Offset(0, 1).Range("A1:A8").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
End Sub
私は、複数の行を選択することによって何を意味するかについてもう少し詳しく知る必要があると思います。したがって、A1とB5を選択した場合、A1とB5から実行したいのですが、異なる列で同じ結果が得られますか? – Histerical
最初の問題は「ActiveCell」を使用していることです。 ActiveCellは1つのセルで、選択されたセルの左上のほとんどのセルとして定義されます。 「選択」を使いたい「ActiveCell」の代わりに – OpiesDad
2番目の問題は、ユーザーがばらばらの範囲を選択した場合です。これを越えるには、split関数を使います:rangeArray = Split(Selection.Address、 "、")そして配列をループします。 – OpiesDad