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】単純作業を自動化したく

Last updated at Posted at 2021-04-16

作業背景

あるディレクトリからファイルを検索し
開いたExcelファイルから特定の文字列を抽出
抽出した文字列を別のExcelに転記したいという内容になります。

登場人物

転記するExcelファイル
転記元情報のExcelファイル

縛り

現場で対応するので
一般的なwindowsで最初から用意されている中で自動化を考えてます。
(本当はpythonやRPAを使ってみたい)

処理

まだ作り始め。
これから更新かけていく予定。
今回は基本の動きを固定値使ってテストして処理が動くかだけ確認。
なので、実際はファイル跨ぎますが、1ファイル内の別シート参照で作っています。
変数名は適当。作りながら変えていきます。


Sub test()
 Call readA
End Sub

Private Function readA()
Dim r As Range

'別シートの値を読み取って転記する
Set r = Worksheets(1).Columns(1)  'Worksheets(1)=1枚目のシート Columns(1)=A列(B列の場合2)
   r.Select 'セル選択
   MaxRow = ActiveCell.End(xlDown).Row 'ActiveCell=選択中のセル .End(xlDown).Row=最後の行番号取得
   Range("B3").NumberFormatLocal = "yyyy/mm/dd"  '書式設定の変更
   Range("B3").Value = Worksheets(1).cells(MaxRow, 1).Value

Set r = Worksheets(1).Columns(2)
   r.Select
   MaxRow = ActiveCell.End(xlDown).Row
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?