/* Rangeは列(column)ファーストで、Cellは行(row)ファースト。Range is column first,cells is row first. */
/* Range is A1 reference style Cells is R1C1 reference style */
Dim str As String
Range("B3").Value="VBAsnippets" ' Range("RowColumn")
str = Range("B3").Value
Debug.Print(str)
Cells(3,2).Value="VBAsnippets" ' Cells(row, column)
str = Cells(3,2).Value
/* Debug is print and breakpoint */
Debug.Print(str)
Worksheets("sheet name").Activate
With Worksheets("Sheet6")
.Activate
.Range("A1").Value = "VBAsnippets"
.Range("A1").RowHeight = 20
.Range("A1").ColumnWidth = 60
End With
With Worksheets("sheet name")
.Activate
With .Range("A1")
.Value = "VBAsnippets"
.RowHeight = 20
.ColumnWidth = 60
End With
End With
Sub AddWorksheet()
Worksheets.Add After:=Worksheets("sheet x")
End Sub
Sub Testfornext()
For i = 1 To 10
Worksheets("sheet name").Cells(i, 1).Value = i
Next
End Sub
For Each e in obj
i = i + 1
Next
If a >= 20 then
Msgbox "OK"
Else
Msgbox "NG"
End If
x = 1
Do Until Cells(x,1).Value = ""
Cells(x,1).Value = Cells(x,1) * 10
x = x + 1
Loop
x = 1
Do While Cells(x,1).Value <> ""
Cells(x,1).Value = Cells(x,1) * 10
x = x + 1
Loop
'/* how to find the last row = 最終行の求めかた */
Dim 最終行 As Long
' 最終行 = Range("A3").End(xlDown).Row + 1 '
With ActiveSheet.UsedRange
最終行 = .Find("*", , xlFormulas, , xlByRows, xlPrevious).Row + 1
End With
' the last day of each Month
DateSerial(year,month,0)
' VBEの画面を黒画面に変身、クールにせよ!
' VBEのメニューから「ツール」の「オプション」で「エディタの設定」タブにで
'・標準コードに対しフォント:MEIRYO UI 、前景:黄色 背景:黒
'・識別子 前景:白、背景:黒
'・キワード 前景:水色、背景:黒
'・コメント 前景:グレー、背景:黒
' how to use Autofilter
Sub Macro1()
With Worksheets("Sheet1")
.Range("A1").AutoFilter _
Field:=3, Criteria1:=">=100"
End With
End Sub
' Methos for cells
Cells.ClearContents 'Clear all the cells without format
Cells.Delete 'Delete all the cells
' Methods for Workbooks Worksheets
Workbooks.Add
Worksheets.Add
Workbooks("Book1.xlsm").Save
ActiveWorkbook.SaveAs("D:\sample.xlsm")
ActiveWorkBook.SaveAs Filename := "d:\sample.xlsm"
ActiveWorkbook.Close
WorkBooks.Open Filename := "d:\sample.xlsm"
Worksheets(1).Activate
Worksheets(2).Select
Worksheets("Sheet1").Copy After := Worksheets("Sheet2")
Worksheets("Sheet1").Move After := Worksheets("Sheet2")
Worksheets("Sheet2").Delete
' camelCaseNotation
RowNumber-> rowNum
ColumnNumber-> colNum
' SnakeNotation
Row_Number->Row_Num
' how to use count property
Workbooks.count finds the current Workbooks
' how to use count prperty example
Sub CommandButton1_Click()
Dim filePath As String
Dim saveFileName String
filePath = ThisWorkbook.Path
saveFileName = "Save" & Year(date) & Month(Date) & Day(Date)
Worksheets("Terget").Copy
Workbooks(Workbooks.count).SaveAs _
filename:=filePath & "\" & saveFileName,FileFormat:=xlCSV, CreateBackup:=False
Workbooks(Worrkbooks.count).Close
End Sub
/* to use EXCEL provided WorksheeteFunctions
Range("A1") = Application.WorksheetFunction.Sum(Range("A1:A10"))