Sub 書込み1() Range("B2").Value = "B2へ記入" Range("C2").Value = "C2へ記入" Range("B3").Value = "B3へ記入" Range("C3").Value = "C3へ記入" End Sub
Sub 書込み2() Dim セル1 As Object Dim セル2 As Object Dim セル3 As Object Dim セル4 As Object Set セル1 = Cells(2, 2) Set セル2 = Cells(2, 3) Set セル3 = Cells(3, 2) Set セル4 = Cells(3, 3) セル1.Value = "B2へ記入" セル2.Value = "C2へ記入" セル3.Value = "B3へ記入" セル4.Value = "C3へ記入" End Sub |
Sub 書込み3() Dim gyou As Integer Dim retu As Integer gyou = 2 retu = 2 Cells(gyou, retu).Value = "B2へ記入" Cells(gyou, retu + 1).Value = "C2へ記入" Cells(gyou + 1, retu).Value = "B3へ記入" Cells(gyou + 1, retu + 1).Value = "C3へ記入" End Sub |
Offset(0,1) ーーー右へ1セル移動 Offset(1,0) ーーー下へ1セル移動 Offset(0,ー1)ーーー左へ1セル移動 Offset(ー1,0)ーーー上へ1セル移動 本例は1セル移動移動ですが、3セル移動の場合は1が3になります。 |
Sub 書込み4() Range("B2").Select ActiveCell.Value = "B2へ記入" ActiveCell.Offset(0, 1).Value = "C2へ記入" ActiveCell.Offset(1, 0).Value = "B3へ記入" ActiveCell.Offset(1, 1).Value = "C3へ記入" End Sub -------------------------------------------------------- Sub 書込み4a() Range("B2").Select ActiveCell.Value = "B2へ記入" ActiveCell.Offset(0, 1).Activate ActiveCell.Value = "C2へ記入" ActiveCell.Offset(1, -1).Activate ActiveCell.Value = "B3へ記入" ActiveCell.Offset(0, 1).Activate ActiveCell.Value = "C3へ記入" End Sub |
Sub 書込み5() Range("B2").Value = "B2へ記入" Range("B2").Cells(1, 2).Value = "C2へ記入" Range("B2").Cells(2, 1).Value = "B3へ記入" Range("B2").Cells(2, 2).Value = "C3へ記入" End Sub |
Sub 書込み6() Range("B2").Select ActiveCell.Value = "B2へ記入" SendKeys "{right}" SendKeys "C2へ記入" SendKeys "{down 1}" SendKeys "{left 1}" SendKeys "B3へ記入" SendKeys "{right}" SendKeys "C3へ記入" SendKeys "{ENTER}" End Sub |
Sub 読取実行() Dim dat1 As String, dat2 As String, dat3 As String On Error Resume Next dat1 = Cells(i + 1, 3).Value 'セルデータがエラー値の場合代入でエラー発生します dat2 = Cells(i + 1, 3).Formula 'セルデータが数式の場合、数式を代入できます dat3 = Cells(i + 1, 3).Text '表示されているセルの状態をそのまま代入できます MsgBox "Valueで読み取り →" & dat1 & Chr(10) & _ "Formulaで読み取り→" & dat2 & Chr(10) & _ "Textで読み取り →" & dat3 End Sub |
Sub 事前確認1() If IsError(Cells(7, 3)) Then MsgBox "セルがエラー値になっています" End If End Sub --------------------------------------------------- Sub 事前確認2() If Cells(6, 3).HasFormula Then MsgBox "セルに関数が設定されています" End If End Sub |
Sub 背景色指定() Cells(2, 2).Select Selection.FormatConditions.Delete Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="1.0" Selection.FormatConditions(1).Interior.ColorIndex = 3 Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="0.02" Selection.FormatConditions(2).Interior.ColorIndex = 38 Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="-0.03" Selection.FormatConditions(3).Interior.ColorIndex = 15 End Sub |