Sub セルの結合() ' ' セルの結合 Macro ' マクロ記録日 : 200x/xx/xx ユーザー名 : xxxxxxxx ' ' Keyboard Shortcut: Ctrl+Shift+C ' With Selection .MergeCells = Not .MergeCells End With End Sub
はじめまして。
とりあえず2つほどネタを・・・
---------
Sub 図形全削除()
For Each sp In ActiveSheet.Shapes
sp.Delete
Next
End Sub
---------
Sub ハイパーリンク全削除()
Cells.Hyperlinks.Delete
End Sub
---------
シートの内容、特に計算式の入っているセルを壊されたくない時にシートの保護をかけたりしますが、複数のシートはひとつひとつ「シートの保護」を実行しなければなりません。そんな時に複数のシートに対して「シートの保護」を実行するマクロです。シートの枚数が何枚でもできるのが、みそです。
----------
'
' シートの保護 マクロ
' マクロ記録日 : 1998/3/26 ユーザー名 : 口車筆無精之助周作
'
'
Sub シートの保護()
I = 0
On Error GoTo Endloop
Do While I >= 0
I = I + 1
Sheets(I).Activate
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Loop
Endloop:
Sheets(1).Activate
End Sub
----------
'
' シートの保護解除 マクロ
' マクロ記録日 : 1998/3/26 ユーザー名 : 口車筆無精之助周作
'
'
Sub シートの保護解除()
I = 0
On Error GoTo Endloop
Do While I >= 0
I = I + 1
Sheets(I).Activate
Application.Goto Reference:="R1C1"
ActiveSheet.Unprotect
Loop
Endloop:
Sheets(1).Activate
End Sub
________________________________________________________
Sub 同じなら結合()
'
' 同じなら結合 Macro
' 同じ値が連続している時上下のセルを結合する
'
'
Dim i As Long, j As Long
Dim myCol As Long
myCol = ActiveCell.Column '現在の列指定
With ActiveSheet
i = 2 '2行目から開始
j = i + 1 'ターゲット行番号
Do While .Cells(j, myCol).Value <> ""
If .Cells(i, myCol).Value = .Cells(j, myCol).Value Then
'同一値では結合
Application.DisplayAlerts = False
.Range(Cells(i, myCol), Cells(j, myCol)) _
.MergeCells = True
Application.DisplayAlerts = True
j = j + 1
Else
i = j
j = j + 1
End If
Loop
End With
End Sub
Sub 同じなら消去()
'
' 同じなら消去 Macro
' 同じ値が連続している時二番目以降のデータを消去する
' 同時に上下間の罫線も消去。列のデータが無くなるまでループ
'
Dim i As Long, j As Long
Dim myCol As Long
myCol = ActiveCell.Column '現在の列指定
With ActiveSheet
i = 2 '2行目から開始
j = i + 1 'ターゲット行番号
Do While .Cells(j, myCol).Value <> ""
If .Cells(i, myCol).Value = .Cells(j, myCol).Value Then
'同一値では消去
.Cells(j, myCol).ClearContents
.Cells(j, myCol).Borders(xlEdgeTop) _
.LineStyle = xlLineStyleNone
j = j + 1
Else
i = j
j = j + 1
End If
Loop
End With
End Sub
________________________________________________________
Sub A1セル選択()
Dim WS As Variant
For Each WS In Worksheets
If Sheets(WS.Name).Visible = True Then
Sheets(WS.Name).Select
Range("A1").Select
End If
Next
Sheets(1).Select
End Sub
Sub 全シートのA1セルを選択()
Dim i As Integer
Application.ScreenUpdating = False
For i = Worksheets.Count To 1 Step -1
Sheets(i).Activate
ActiveSheet.Range("A1").Select
ActiveWindow.SmallScroll Down:=65536, Up:=65536, ToRight:=256, ToLeft:=256
Next i
Application.ScreenUpdating = True
End Sub
拡大と縮小。コマンドバーにあるズームコンボボックスや、追加できる画面表示拡大・縮小ボタンでも良いのですが、
・10 % や 400 % にしたい
・ショートカットキーに割り当てたい
ので作りました。私は、拡大を Ctrl+Insert、縮小を Ctrl + Delete に割り当てています。便利です。(^^)
-------------------------------------------------
Public Sub ActiveWindow_ZoomUp()
Window_EscalationZoom ActiveWindow, 1
End Sub
Public Sub ActiveWindow_ZoomDown()
Window_EscalationZoom ActiveWindow, -1
End Sub
Private Sub Window_EscalationZoom(ByVal wn As Window, ByVal ZoomOffset As Long)
Dim arZooms As Variant
Dim ixZoom As Long
Dim i As Long
On Error Resume Next
If ZoomOffset = 0 Then Exit Sub
arZooms = Array(10, 25, 50, 75, 100, 200, 400)
ixZoom = UBound(arZooms)
For i = 0 To UBound(arZooms) - 1
If wn.Zoom = arZooms(i) Then
ixZoom = i
Exit For
ElseIf wn.Zoom < arZooms(i + 1) Then
If Sgn(ZoomOffset) = 1 Then
ixZoom = i
Else
ixZoom = i + 1
End If
Exit For
End If
Next
ixZoom = ixZoom + ZoomOffset
If ixZoom < 0 Then
ixZoom = 0
ElseIf UBound(arZooms) < ixZoom Then
ixZoom = UBound(arZooms)
End If
If Not (wn.Zoom = arZooms(ixZoom)) Then
wn.Zoom = arZooms(ixZoom)
End If
End Sub