hiko-blog

VBA業務改善

MENU

2024-04-01から1ヶ月間の記事一覧

条件に応じてコピー

VBA

Sub CopyFormulasBasedOnCriteria() Dim wsSource As Worksheet Dim wsTemplate As Worksheet Dim lastRow As Long Dim i As Long Dim copyRow As Long Dim pasteRow As Long ' シートをセットアップ Set wsSource = ThisWorkbook.Sheets("Data") Set wsTemp…

判別して記入

VBA

Sub 判別して記入() Dim ws1 As Worksheet Dim ws2 As Worksheet Dim lastRow1 As Long Dim lastRow2 As Long Dim keyRange As Range Dim cell As Range Dim keyArray() As Variant Dim keyIndex As Long Dim labels() As String Dim labelIndex As Long Dim…

コピー転記してから色付け

VBA

Sub コピー転記してから色付け() Dim wsSource As Worksheet Dim wsDestination As Worksheet Dim wsKeywords As Worksheet Dim lastRowSource As Long Dim lastRowKeywords As Long Dim i As Long Dim j As Long Dim keyword As String ' Sheet1をソース、S…

振分 (正規表現)

VBA

Sub UpdateDColumnWithRegex() Dim regex As Object Dim lastRow As Long Dim i As Long ' 正規表現オブジェクトを作成 Set regex = CreateObject("VBScript.RegExp") ' パターンを設定 regex.IgnoreCase = True regex.Global = True ' 最終行を取得 lastRow…

2つのKEYを比較し、お互いに存在しないKEYを別シートに抽出する

VBA

Sub 比較と記載1() ’Dictionaryにてremoveメソッド利用(ないものを削除パターン) Dim ws As Worksheet Dim lastRow1, lastRow2 As Long Dim aRange As Range, cRange As Range Dim aValue As Variant, cValue As Variant Dim compareColumnA As Range, compa…

ヒットする項目を抽出する

VBA

Sub TransferData() Dim ws1 As Worksheet Dim ws2 As Worksheet Dim lastRow1 As Long Dim lastRow2 As Long Dim i As Long Dim j As Long Dim keyA As String Dim keyB As String Dim matchFound As Boolean ' Sheet1とSheet2を設定 Set ws1 = ThisWorkboo…

指定された日付から60日後の日付を計算

VBA

Sub 前日の日付を計算してセルに入力() Dim 検索日 As Date Dim 前日 As Date Dim 後日 As Date Dim フォーマット済み日付 As String Dim 休みの日 As Range ' セルA1に入力された日付を取得(ここではA1を例示しています) 検索日 = Range("A1").Value ' 休…

ワークデイ関数を使って指定した日付の前日を計算

VBA

Sub 前日の日付を計算してセルに入力() Dim 検索日 As Date Dim 前日 As Date Dim フォーマット済み日付 As String Dim 休みの日 As Range ' セルA1に入力された日付を取得(ここではA1を例示しています) 検索日 = Range("A1").Value ' 休みの日をシート2の…

指定年、月と前後月 土日検索

VBA

Sub ExtractWeekendAndHolidayDatesByMonth(yearToSearch As Integer, monthToSearch As Integer) Dim startDate As Date Dim endDate As Date Dim currentDate As Variant Dim ws As Worksheet Dim rowNum As Long Dim holidayDates As Variant Dim i As In…

毎月の土曜日と日曜日 抽出

VBA

Sub ExtractWeekendDates() Dim startDate As Date Dim endDate As Date Dim currentDate As Date Dim ws As Worksheet Dim rowNum As Long ' 新しいシートを作成します Set ws = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.C…

日本の休日を考慮して土曜日と日曜日を検索

VBA

Sub ExtractWeekendAndHolidayDatesByYear(yearToSearch As Integer) Dim startDate As Date Dim endDate As Date Dim currentDate As Date Dim ws As Worksheet Dim rowNum As Long Dim holidayDates As Variant Dim i As Integer ' 新しいシートを作成しま…

クリア (列全体 EntireColumn)

VBA

Sub Sample() Range("B2:D5").EntireColumn.ClearEnd Sub

重複削除

VBA

Sub Sample() Range("A:C").RemoveDuplicates(Array(1, 2, 3))End Sub

条件 振り分け2

VBA

Sub UpdateDColumnWithRegex555() Dim regex As Object Dim lastRow As Long Dim i As Long '参照設定 Microsoft VBScript Regular Expressions 5.5 ' 正規表現オブジェクトを作成 Set regex = CreateObject("VBScript.RegExp") ' パターンを設定 regex.Igno…