[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『日付を入力すれば(マクロ)その日付のセル(エクセル)に移動する』(ぬぬ)
A1に4/1, B1に4/2, C1に4/3・・・があり、マクロを使用し、入力フォームに
日付を入力すると、その該当セルに移動するようにしたいのですが。
どのようなマクロにすればよいか、お願いします。
< 使用 Excel:Excel2019、使用 OS:Windows10 >
横から失礼します。
参考まで。
Application.Dialogs(xlDialogFormulaFind).Show Date ( MK) 2022/11/30(水) 10:01:27
マクロでどのように表現すれば、よいでしょうか。 Columns・・・
お願いします。
(ぬぬ) 2022/11/30(水) 17:51:04
こんにちは
Application.Dialogs(xlDialogFormulaFind).Show Date 後に 11/27がB列にあるとした場合です。どこにペーストするかは 微調整してください。下記のレイアウトは、11/27で検索した結果です。
◇Sheet1 コピー元シート
|[A] |[B] |[C] |[D] |[E] |[F] |[G]
[1]|11月26日|11月27日|11月28日|11月29日|11月30日|12月1日|12月2日
[2]|A2 |B2 |C2 |D2 |E2 |F2 |G2
[3]|A3 |B3 |C3 |D3 |E3 |F3 |G3
[4]|A4 |B4 |C4 |D4 |E4 |F4 |G4
[5]|A5 |B5 |C5 |D5 |E5 |F5 |G5
[6]|A6 |B6 |C6 |D6 |E6 |F6 |G6
[7]|A7 |B7 |C7 |D7 |E7 |F7 |G7
◇Sheet2 転記後結果
|[A]
[1]|
[2]|B2
[3]|B3
[4]|B4
[5]|B5
[6]|B6
[7]|B7
Sample1 は、1セルずつお引越しタイプです。 1行目の日付のフォントを、解りやすく赤色にして みました。★の行を取っ払っても動きます。
Sample2 は、一括貼り付けタイプです。 こちらが一般的ですが、書き方はまだ他にもあります。
Sub Sample1()
Dim ws(1 To 2) As Worksheet
Dim i As Long, LastRow As Long, LastCol As Long
Set ws(1) = Sheets(1) '' コピー元
Set ws(2) = Sheets(2) '' ペースト先
Application.Dialogs(xlDialogFormulaFind).Show Date
Selection.Font.ColorIndex = 3 '' ★
LastRow = ws(1).Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
LastCol = ws(1).Cells(1, Columns.Count).End(xlToLeft).Column
If ActiveCell.Font.ColorIndex = 3 Then '' ★
For i = 2 To LastRow
ws(2).Cells(i, 1).Value = ws(1).Cells(i, ActiveCell.Column).Value
Next
End If '' ★
End Sub
Sample2()
Dim ws(1 To 2) As Worksheet
Dim LastRow As Long, LastCol As Long
Set ws(1) = Sheets(1) '' コピー元
Set ws(2) = Sheets(2) '' ペースト先
Application.Dialogs(xlDialogFormulaFind).Show Date
LastRow = ws(1).Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
LastCol = ws(1).Cells(1, Columns.Count).End(xlToLeft).Column
Application.ScreenUpdating = False
ws(1).Range(ws(1).Cells(2, ActiveCell.Column), _
ws(1).Cells(LastRow, ActiveCell.Column)).Copy
ws(2).Range(ws(2).Cells(2, 1), ws(2).Cells(LastRow, 1)) _
.PasteSpecial xlPasteAll
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
(あみな) 2022/12/01(木) 13:01:59
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.