
Power Girl

Super Girl




Sub copy_paste_special()
'Sử dụng phương thức Range.PasteSpecial để dán dữ liệu copy
'Copy và PasteSpecial trongrange
Range("A1").Copy
Range("A3").PasteSpecial Paste:=xlPasteFormats
'Copy và PasteSpecial giữa các worksheets
Worksheets("Sheet1").Range("A2").Copy
Worksheets("Sheet2").Range("A2").PasteSpecial Paste:=xlPasteFormulas
'Copy và PasteSpecial giữa các workbooks
Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("A1").Copy
Workbooks("Book2.xlsx").Worksheets("Sheet1").Range("A1").PasteSpecial Paste:=xlPasteFormats
'Xóa đường viền copy xung quanh khu vực chọn copy
Application.CutCopyMode = False
End Sub
Sub copy_paste_simple()
'Sử dụng phương thức Range.Copy cho copy/paste
'Phương thức Range.Copy để Copy & Paste trên một dòng
Range("A1").Copy Range("C1")
Range("A1:A3").Copy Range("D1:D3")
Range("A1:A3").Copy Range("D1")
'Range.Copy trên các worksheets khác nhau
Worksheets("Sheet1").Range("A1").Copy Worksheets("Sheet2").Range("A1")
'Range.Copy trên các workbooks khác nhau
Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("A1").Copy _
Workbooks("Book2.xlsx").Worksheets("Sheet1").Range("A1")
End Sub
Sub Paste_Values_Examples()
'Set the cells' values equal to another to paste values
'Set a cell's value equal to another cell's value
Range("C1").Value = Range("A1").Value
Range("D1:D3").Value = Range("A1:A3").Value
'Set values between worksheets
Worksheets("Sheet2").Range("A1").Value = Worksheets("Sheet1").Range("A1").Value
'Set values between workbooks
Workbooks("Book2.xlsx").Worksheets("Sheet1").Range("A1").Value = _
Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("A1").Value
End Sub
Sub Dienthoai()
Dim i As Integer
Dim LastRow1 As Long
LastRow1 = Worksheets("Free 50k").Cells(4, "B").End(xlDown).Row
Application.Interactive = False
Application.EnableEvents = False
Application.ScreenUpdating = False
For i = 4 To LastRow1
'Cells(i, 11).Value = "=INDEX(Data!B:F,MATCH(B4,Data!B:B,0),5)"
Cells(i, 11).Value = Application.Index(Worksheets("data").Range("B:F"), Application.Match(Range("B" & i), Worksheets("data").Range("B:B"), 0), 5)
Next i
Application.Interactive = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Sub Select_File_Or_Files_Windows()
Dim SaveDriveDir As String
Dim MyPath As String
Dim Fname As Variant
Dim N As Long
Dim FnameInLoop As String
Dim mybook As Workbook
' Save the current directory.
SaveDriveDir = CurDir
' Set the path to the folder that you want to open.
MyPath = Application.DefaultFilePath
' You can also use a fixed path.
'MyPath = "C:\Users\Ron de Bruin\Test"
' Change drive/directory to MyPath.
ChDrive MyPath
ChDir MyPath
' Open GetOpenFilename with the file filters.
Fname = Application.GetOpenFilename( _
FileFilter:="Excel Files (*.xls), *.xlsx", _
Title:="Select a file or files", _
MultiSelect:=True)
' Perform some action with the files you selected.
If IsArray(Fname) Then
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
For N = LBound(Fname) To UBound(Fname)
' Get only the file name and test to see if it is open.
FnameInLoop = Right(Fname(N), Len(Fname(N)) - InStrRev(Fname(N), Application.PathSeparator, , 1))
If bIsBookOpen(FnameInLoop) = False Then
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(Fname(N))
On Error GoTo 0
If Not mybook Is Nothing Then
MsgBox "You opened this file : " & Fname(N) & vbNewLine & _
"And after you press OK, it will be closed" & vbNewLine & _
"without saving. You can replace this line with your own code."
mybook.Close SaveChanges:=False
End If
Else
MsgBox "We skipped this file : " & Fname(N) & " because it is already open."
End If
Next N
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If
' Change drive/directory back to SaveDriveDir.
ChDrive SaveDriveDir
ChDir SaveDriveDir
End Sub
Function bIsBookOpen(ByRef szBookName As String) As Boolean
' Contributed by Rob Bovey
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function
Fname = Application.GetOpenFilename( _
FileFilter:="XLS Files (*.xls),*.xls,CSV Files (*.csv),*.csv", _
Title:="Select a file or files", _
MultiSelect:=True)
.ghost-button { display: inline-block; width: 200px; padding: 8px; color: #fff; border: 2px solid #fff; text-align: center; outline: none; text-decoration: none; transition: background-color 0.2s ease-out, color 0.2s ease-out; } .ghost-button:hover, .ghost-button:active { background-color: #fff; color: #000; transition: background-color 0.3s ease-in, color 0.3s ease-in; }Cách sử dụng: class=”ghost-button”. Ví dụ: Nếu bạn muốn thêm một download link, thì làm như dưới đây<a class="ghost-button" href="link cần">Download Now</a>
Sub Macro1()
Dim i As Integer, j As Integer, a As Integer, b As Integer, kq As Integer
Dim LastRow1 As Long
Dim LastRow2 As Long
Dim Macro1 As Integer
Dim Total As Integer
LastRow1 = Worksheets("Data").Cells(2, "H").End(xlDown).Row
LastRow2 = Worksheets("Data").Cells(2, "I").End(xlDown).Row
' Tìm vị trí của hàng có chữ Macro1
Macro1 = Application.Match("Macro1", Worksheets("sheet2").Range("A:A"), 0)
' Tìm vị trí của hàng có chữ Total
Total = Application.Match("TOTAL", Worksheets("sheet2").Range("A:A"), 0)
Application.Interactive = False
Application.EnableEvents = False
Application.ScreenUpdating = False
For i = Macro1 + 1 To Total - 1 ' Chạy vòng lặp từ vị trí đứng dưới chữ Macro đến vị trí đứng trên chữ total
a = 0
b = 0
kq = 0
For j = 4 To 29
a = Application.CountIfs(Worksheets("Data").Range("H2:H" & LastRow1), Worksheets("sheet2").Range("B" & i), Worksheets("Data").Range("I2:I" & LastRow2), Worksheets("sheet2").Cells(1, j))
b = Application.CountIfs(Worksheets("Data").Range("H2:H" & LastRow1), Worksheets("sheet2").Range("C" & i), Worksheets("Data").Range("I2:I" & LastRow2), Worksheets("sheet2").Cells(1, j))
kq = a + b
Cells(i, j).Value = kq
Next j
Next i
Application.Interactive = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub