0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【VBA】単純作業を自動化したく その2

Last updated at Posted at 2021-04-20

元の記事

進捗

今回は「③表題の文字列を検索する」
「④③の文字列の位置から「別シートの値を読み取って転記する」を実施」ができました。
前回の差分としては固定のセルだったところを検索した文字列を起点として処理ができるようになっています。
調べながらなので、ソース汚いとかはありますが気になさらず。

Sub test()
 Call readA
End Sub

Private Function readA()
Dim r As Rang
Dim myRng As Range

'別シートの値を読み取って転記する
'Set r = Worksheets(1).Columns(1)  'Worksheets(1)=1枚目のシート Columns(1)=A列(B列の場合2)
Set r = Worksheets("test").Columns().Find(What:="日付", LookIn:=xlValues, Lookat:=xlWhole)
'Debug.Print (r.Address(External:=True))
  With Worksheets("test")
   MaxRow = .cells(.Range(r.Address(External:=True)).Row, .Range(r.Address(External:=True)).Column).End(xlDown).Row 'ActiveCell=選択中のセル .End(xlDown).Row=最後の行番号取得
  End With
   Sheets(2).Activate
   Range("B3").NumberFormatLocal = "yyyy/mm/dd"  '書式設定の変更
   Range("B3").Value = Worksheets(1).cells(MaxRow, 1).Value
'Set r = Worksheets(1).Columns(2)
Set r = Worksheets("test").Columns().Find(What:="版数", LookIn:=xlValues, Lookat:=xlWhole)
   'r.Select
   With Worksheets("test")
   MaxRow = .cells(.Range(r.Address(External:=True)).Row, .Range(r.Address(External:=True)).Column).End(xlDown).Row 'ActiveCell=選択中のセル .End(xlDown).Row=最後の行番号取得
  End With
   Sheets(2).Activate
Range("C3").Value = Worksheets(1).cells(MaxRow, 2).Value
   
   'TODO
   '①excelファイルを開く
   '②一定のディレクトリで①をループさせる
   '③表題の文字列を検索する
   '④③の文字列の位置から「別シートの値を読み取って転記する」を実施
   '⑤③から④を繰り返す
 
End Function
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?