Skip to content

Instantly share code, notes, and snippets.

ndthanh / HEO-tim-dong-cuoi.bas
Last active December 22, 2016 08:40
Học Excel Online - tìm dòng cuối, cột cuối
lastRow = Range("A" & Sheet1.Rows.Count).End(xlUp).Row
lastcol = Range("A" & Sheet1.Columns.Count).End(xlToLeft).Column
Sub test()
Dim rg As Range, row As Range
Set rg = Sheet1.Range("B2").CurrentRegion
For Each row In rg.Rows
' in ra cửa sổ Immediate Window(Ctrl + G)
Debug.Print row.Cells(1, 1)
End Sub
Sub test()
Dim i As Long
For i = 2 To rg.Rows.Count
'in ra cửa sổ Immediate Window(Ctrl + G)
Debug.Print rg.Cells(i, 1)
End Sub
#lấy toàn bộ các cột báo cáo
SELECT * FROM [A1:U42000]
SELECT [Order ID],[Order Date],[Order Quantity],[Order Priority] ,[Customer Name] FROM [A1:U42000] WHERE [Order Priority] = "High"
SELECT [Order ID],[Order Date],[Order Quantity],[Customer Name] FROM [A1:U42000] WHERE [Order Priority] = "High" AND [Customer Name] = "Annie Cyprus"
SELECT [Order ID],[Order Date],[Order Quantity],[Customer Name],[Ship Mode] FROM [A1:U42000] WHERE [Order Priority] = "High" AND [Ship Mode] LIKE "%Air"
Sub LastRowInOneColumn()
'Tìm dòng cuối cùng có dữ liệu trong cột A
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
MsgBox LastRow
End Sub
Sub LastColumnInOneRow()
'Find the last used column in a Row: row 1 in this example
Dim LastCol As Integer
With ActiveSheet
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
MsgBox LastCol
End Sub
Sub Range_SpecialCells_Method()
    MsgBox Range("A1").SpecialCells(xlCellTypeLastCell).Address
End Sub
Sub Range_Find_Method()
'Finds the last non-blank cell on a sheet/range.
Dim lRow As Long
Dim lCol As Long
    lRow = Cells.Find(What:="*", _
                    After:=Range("A1"), _
                    LookAt:=xlPart, _
                    LookIn:=xlFormulas, _
Public Sub dem_so_sheets()
MsgBox "So sheet trong bang tinh nay la " & Application.Sheets.Count
End Sub