サイト紹介

メール補助マクロ

更新日:

‘ デスクトップを開く
Set objShell = CreateObject(“WScript.Shell”)
objShell.Run “explorer.exe C:\Users\hiro8\Desktop\test”

Sub シート名取得()
Dim ws As Worksheet
Dim targetRange As Range
Dim cell As Range
Dim sheetName As String
Dim count As Integer ‘ カウントをループ外で宣言

Set targetRange = Range(“B8:B100”) ‘ B8セル以下の範囲を指定

For Each ws In Worksheets ‘ 各ワークシートに対して処理を実行
sheetName = ws.Name
count = 0 ‘ カウントの初期化をループの始めで行う

‘*******************************************
For Each cell In targetRange
If InStr(1, cell.Value, sheetName) > 0 Then count = count + 1
Next cell
Debug.Print count
‘*******************************************

If count = 0 Then
For Each cell In targetRange
If cell.Value = “” Then
cell.Value = sheetName
Exit For
End If
Next cell
End If
Next ws
End Sub

Sub シート整列()

‘ 指定したシート名
Dim targetSheetName As String
Dim moveSheetName As String

For i = 1 To 100
targetSheetName = Sheets(“TOP”).Cells(i + 7, 2)
moveSheetName = Sheets(“TOP”).Cells(i + 8, 2)
Debug.Print targetSheetName; “、” & moveSheetName & “の順番に。”

Sheets(moveSheetName).Move after:=Sheets(targetSheetName)

Next i
End Sub

-サイト紹介

Copyright© 暮らしの知恵 , 2023 All Rights Reserved Powered by STINGER.