ExcelVBAへの道
|
Sub
選択範囲コピー() Worksheets("Sheet1").Cell(1,1).CurrentRegion.Select Selection.Copy Destination := Range("G9") 'G9のセルに貼り付け End Sub -------------------------------------------------------------------------- Sub 選択範囲切取り() Worksheets("Sheet1").Cell(1,1).CurrentRegion.Select Selection.Cut ActiveSheet.Paset Destination := Range("G9") 'G9のセルに貼り付け End Sub ---------------------------------------------------------------------------- Sub 書式コピー() Dim syosiki As String syosiki = Range("A:A").NumberFormat Range("G:G").NumberFormat = syosiki End Sub ----------------------------------------------------------------------------- Sub データクリア() = "" End Sub ----------------------------------------------------------------------------- Sub データと書式クリア() With ActiveWindow.RangeSelection .ClearFormats .ClearContents End With End Sub ------------------------------------------------------------------------------- Sub 全てクリア() ActiveWindow.RangeSelection.Cells.ClearContents End Sub ------------------------------------------------------------------------------ Sub 書体変更() With ActiveWindow.RangeSelection .Font.Name = "HGP行書体" End With End Sub ----------------------------------------------------------------- Sub 選択範囲削除() ActiveWindow.RangeSelection.Delete End Sub ------------------------------------------------ Sub 表示形式設定() ActiveWindow.RangeSelection.NumberFormat = "0%" End Sub ----------------------------------------------------------------------- Sub 背景色設定() With Selection.Interior .ColorIndex = 6 .Pattern = xlSolid End With End Sub ------------------------------------------------------------------------ Sub 文字色変更() ActiveWindow.RangeSelection.Font.Color = RGB(0,0,255) End Sub ------------------------------------------------------------------------ Sub 文字位置() ActiveWindow.RangeSelection.HorizontalAlignment = xlHalignRight ' ActiveWindow.RangeSelection.HorizontalAlignment = xlHalignLeft ' ActiveWindow.RangeSelection.HorizontalAlignment = xlHalignDistributed ' ActiveWindow.RangeSelection.HorizontalAlignment = xlHalignGeneral End Sub -------------------------------------------------------------------------- Sub アクティブセルを画面左上隅に表示() With Selection Application.Goto Reference:=ActiveCell, Scroll:=True End With End Sub ----------------------------------------------------------------------------- Sub 行数カウント() Dim gyou As integer gyou = Range("A1").CurrentRegion.Rows.Count MsgBox"行数=" & gyou End Sub ----------------------------------------------------------------------------- Sub 新規入力セルに移動() Range("A65536").Select Selection.End(xlUp).Select Selection.Offset(1).select End Sub ----------------------------------------------------------------------------- Sub 選択範囲に外枠罫線を引く() With Selection.CurrentRegion.Select Selection.BorderAround ColorIndex := 5, Weight:=xlMedium End With End Sub ----------------------------------------------------------------------------- Sub 降順で並べ替え() Range("C25").Sort Key1:=Range("D25"), Order1:=xlDescending End Sub |