教えて頂ければと投稿しました。
・・C・・D・・E・・F・・G・・H
3・abc・・・15・・・20・・・・・・・・・・・・・・・
4・def・・・10・・・10・・abc・・・15・・・10
5・ghi・・・・5・・・・5・・・・・・・・・・・・・・・・・
6・jkl・・・・8・・・・30・・ghi・・・・1・・・・5
以下続く
このような表があった場合に、C行とF行が同じ値のものを横並べにして、D行、E行はそのまま横並び、G行、H行もそのまま横並びにして表を完成させたいです。このようなマクロをご教示して頂きたくよろしくお願いいたします。
完成型
・・C・・D・・E・・F・・G・・H
3・abc・・・15・・・20・・abc・・・15・・・10
4・def・・・10・・・10・・・・・・・・・・・・・・・
5・ghi・・・・5・・・・5・・・ghi・・・・1・・・・5
6・jkl・・・・8・・・・30・・・・・・・・・・・・・・・・
以下続く
No.1ベストアンサー
- 回答日時:
以下のマクロを標準モジュールに登録してください。
Option Explicit
Public Sub 並べ替え()
Dim dicT As Object
Dim dicR As Object
Dim ws As Worksheet
Dim maxrow1 As Long
Dim maxrow2 As Long
Dim arr As Variant
Dim wrow As Long
Dim srow As Long
Dim key As Variant
Set dicT = CreateObject("Scripting.Dictionary")
Set dicR = CreateObject("Scripting.Dictionary")
Set ws = ActiveSheet
maxrow1 = ws.Cells(Rows.Count, "C").End(xlUp).Row
maxrow2 = ws.Cells(Rows.Count, "F").End(xlUp).Row
arr = ws.Range("F1:H" & maxrow2)
For wrow = 3 To maxrow2
key = ws.Cells(wrow, "F").Value
If key <> "" Then
If dicT.exists(key) = False Then
dicT(key) = wrow
End If
End If
Next
For wrow = 3 To maxrow1
key = ws.Cells(wrow, "C").Value
If dicT.exists(key) = True Then
srow = dicT(key)
ws.Cells(wrow, "F").Value = key
ws.Cells(wrow, "G").Value = arr(srow, 2)
ws.Cells(wrow, "H").Value = arr(srow, 2)
dicR(wrow) = True
If dicR.exists(srow) = False Then
ws.Cells(srow, "F").Resize(1, 3).ClearContents
End If
End If
Next
MsgBox ("完了")
End Sub
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
特定のPCだけ動作しないVBAマク...
-
Excel・Word リサーチ機能を無...
-
一つのTeratermのマクロで複数...
-
Excel マクロ VBA プロシー...
-
メッセージボックスのOKボタ...
-
エクセルに張り付けた写真のフ...
-
エクセルで特定の列が0表示の場...
-
特定文字のある行の前に空白行...
-
ExcelのVBA。public変数の値が...
-
Excel マクロでShearePoint先の...
-
wordを起動した際に特定のペー...
-
TERA TERMを隠す方法
-
マクロ実行時、ユーザーフォー...
-
エクセルで別のセルにあるふり...
-
ExcelVBAでPDFを閉じるソース
-
Worksheet_Change(ByVal Target...
-
エクセルマクロでワードの一ペ...
-
VBA アドインについて お詳しい...
-
VBAのIF分で時間指定の条件式の...
-
Excel_マクロ_現在開いているシ...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
特定のPCだけ動作しないVBAマク...
-
Excel・Word リサーチ機能を無...
-
エクセルで特定の列が0表示の場...
-
Excel マクロ VBA プロシー...
-
メッセージボックスのOKボタ...
-
一つのTeratermのマクロで複数...
-
ExcelのVBA。public変数の値が...
-
エクセルに張り付けた写真のフ...
-
Excel VBAからAccessマクロを実...
-
Excel マクロでShearePoint先の...
-
特定文字のある行の前に空白行...
-
エクセルで別のセルにあるふり...
-
TERA TERMを隠す方法
-
wordを起動した際に特定のペー...
-
マクロ実行時、ユーザーフォー...
-
ExcelVBAでPDFを閉じるソース
-
【EXCEL VBA】オートシェイプを...
-
Excel_マクロ_現在開いているシ...
-
EXCELマクロでのThisisWor...
-
ソース内の行末に\\
おすすめ情報