Thầy ơi, sao em bấm sắp xếp mà nó sắp xếp lộn xộn vậy?
Thầy ơi, sao em bấm sắp xếp mà nó sắp xếp lộn xộn vậy?
Chào bạn bạn xem đang sắp xếp theo cột nào?
Cột Khu Vực á thầy. Thầy xem lại cho em cái code với
Sub test()
'
' Test Macro
'
'Chon o A1
Range("A1").Select
'Nhap chu vao Ten vao
ActiveCell.FormulaR1C1 = "Ten"
Range("A2").Select 'Chon o A2
ActiveCell.FormulaR1C1 = "A"
Range("A3").Select
ActiveCell.FormulaR1C1 = "B"
Range("A4").Select
ActiveCell.FormulaR1C1 = "C"
Range("A5").Select
ActiveCell.FormulaR1C1 = "D"
Range("B1").Select
ActiveCell.FormulaR1C1 = "So luong"
Range("B2").Select
ActiveCell.FormulaR1C1 = "1"
Range("B3").Select
ActiveCell.FormulaR1C1 = "2"
Range("B4").Select
ActiveCell.FormulaR1C1 = "3"
Range("B5").Select
ActiveCell.FormulaR1C1 = "4"
Range("B6").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-4]C+R[-3]C+R[-2]C+R[-1]C)"
Range("A1:B6").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
MsgBox "Ok"
End Sub
Sub Macro2()
'
' Macro2 Macro
'
'
Range("A2:A20").Select
ActiveSheet.Range("$A$1:$A$20").RemoveDuplicates Columns:=1, Header:=xlYes
Range("B1").Select
MsgBox "Xóa trùng thành công!"
End Sub
Sub Macro3()
'
' Macro3 Macro
'
'
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("A2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A2:A13")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Sub Macro4()
'
' Macro4 Macro
'
'
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("A2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A2:A10")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
thầy ơi sao khi mình search nó chỉ ra có bài ở trên không có bài ở dưới vậy
thay cho xin doan code do dc ko ạ
Chào bạn bạn lấy code tại đây nhé:
cách tải tài liệu thê nào vậy gitiho ơi.
Chào bạn Ở phía dưới video bài học có các mục Hỏi đáp - Tài liệu tải về - Nội dung tóm tắt - Giảng viên, bạn bấm vào mục Tài liệu tải về, trong đó sẽ có tài liệu và nút bấm tải về bạn nhé. với bài học nào có tài liệu thì tab tài liệu sẽ có nút cho bạn tải nhé.
Ở đây tài liệu đầu vào bạn tải chương 0 bài 2 nhé.
LÀM THẾ NÀO ĐỂ TEXTBOX TRONG FORM HIỆN SẲN DỮ LIỆU KHI FORM ĐƯỢC GỌI?
VD: TEXTBOX NĂM SẼ HIỂN THỊ DỮ LIỆU CỦA C1 TRONG SHEET5
THANKS
Bạn thiết lập trong lệnh:
Private Sub UserForm_Initialize()
End Sub
Những đoạn code trong lệnh này sẽ được chạy ngay khi bạn gọi Userform lên.
Thanks Thầy nhiều ạ, cho em hỏi thêm.
làm thế nào để vòng if hoạt động theo điều kiện như sau:
có 3 cột a b c và 3 dòng 1 2
Nếu dòng 2 của 3 cột = 0 thì msb "không thay đổi"
ngược lại nếu dòng 2 của 3 cột (bất kỳ cột nào) khác 0 thì sẽ tự thêm dữ liệu vào dòng 1 của cột tương ứng.
Mong thầy giúp đỡ
Private Sub cmdAdd_Click()
Dim RowNum As Long
Dim ListBoxRow As Long
Worksheets("Form").Activate
RowNum = Application.CountA(Range("A:A")) + 2
ListBoxRow = lstSearchResults.ListIndex + 2
Cells(RowNum, 1).Value = Worksheets("Product Search").Cells(ListBoxRow, 1).Value
Unload Me
End Sub
Private Sub cmdSearch_Click()
Dim RowNum As Long
Dim SearchRow As Long
RowNum = 2
SearchRow = 2
Worksheets("Stock Data").Activate
Do Until Cells(RowNum, 1).Value = ""
If InStr(1, Cells(RowNum, 2).Value, txtKeywords.Value, vbTextCompare) > 0 Then
Worksheets("Product Search").Cells(SearchRow, 1).Value = Cells(RowNum, 1).Value
Worksheets("Product Search").Cells(SearchRow, 2).Value = Cells(RowNum, 2).Value
Worksheets("Product Search").Cells(SearchRow, 3).Value = Cells(RowNum, 3).Value
SearchRow = SearchRow + 1
End If
RowNum = RowNum + 1
Loop
If SearchRow = 2 Then
MsgBox "No products were found that match your search criteria."
Exit Sub
End If
lstSearchResults.RowSource = "SearchResults"
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
txtKeywords.SetFocus
Worksheets("Product Search").Range("A2:C100").ClearContents
End Sub
thầy ơi e nhờ thầy chút ạ
e có bảng lít danh sách e muốn chọn và dữ liệu sang cột B , thầy xem đoạn code kia chỉnh như nào để sang dk cột B ạ
cảm ơn thầy !