Mọi người giúp mình sửa 2 đoạn VBA này với ạ! (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

hoangthao2015

Premier Сasual Dating - Actual Women
Tham gia
27/2/17
Bài viết
3
Được thích
0
Giới tính
Nam
Nghề nghiệp
Health
Public sh, rnga, cbb As String
Public cot, cot2, cotxuat2, cotdotim As Integer
Private Sub mosheet1()
sh = "danhmuc" 'ten sheet chua vung dau vao
rnga = "mahang01" 'ten vung do tim
cbb = "combobox1" 'teen combobox tren userform
cot = 0 'khoang truong lay gia tri thu nhat so voi vung do tim
cot2 = 1 'khoang truong lay gia tri thu 2 so voi voi vung do tim
cotxuat2 = 1 'khoang cach cua vung xuat du lieu thu 2 so voi vung xuat gia tri hien hanh
cotdotim = 1 'cot chua gia tri do tim trong combobox
sheetname.Show False
End Sub
Sub test()
If Not (Intersect(Selection, Sheet2.Range("daura")) Is Nothing) Then
Call mosheet1
End If
End Sub










Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If (KeyCode < 37 Or KeyCode > 41) And KeyCode <> 13 Then
st = Me.Controls(cbb).Text
Call timdoituong(Sheets(sh).Range(rnga), Me.Controls(cbb))
Me.Controls(cbb).Text = st
End If


End Sub




Private Sub timdoituong(ma As Range, cbo)

Dim mang(1 To 10000, 1 To 2)
Dim tim, odau As Range
Dim k, cotx, cotconlai As Integer
cotx = IIf(cotdotim = 1, cot2, cot)
cotconlai = IIf(cotdotim = 1, 2, 1)


Set tim = ma.Find((cbo.Text) & "*")
If Not tim Is Nothing Then
Set odau = tim
mang(1, cotdotim) = tim.Value
mang(1, cotconlai) = tim.Offset(, cotx).Value
k = 1
Else
cbo.Clear
Exit Sub
End If

Set tim = ma.FindNext(tim)

Do While tim.Address <> odau.Address
k = k + 1
mang(k, cotdotim) = tim.Value
mang(k, cotconlai) = tim.Offset(, cotx).Value
Set tim = ma.FindNext(tim)
Loop
cbo.Clear
cbo.List = mang

End Sub
Private Sub CommandButton1_Click()
Dim JK As Range
On Error GoTo thoat
If Me.Controls(cbb).Text = "" Then Exit Sub


If WorksheetFunction.CountIf(Range(rnga), Me.Controls(cbb).Value) = 0 Then
MsgBox "Sai ma hang"
Me.Controls(cbb).SetFocus
Exit Sub
End If


For Each rng In Range(rnga)
If rng.Value = Me.Controls(cbb).Text Then
Selection.Value = Me.Controls(cbb).Text
Selection.Offset(, cotxuat2).Value = rng.Offset(, cot2).Value
Unload Me
Exit Sub
End If
Next
thoat:
End Sub


Private Sub UserForm_Activate()
With Me.Controls(cbb)
.ColumnCount = 2
.BoundColumn = cotdotim
.ListWidth = "350pt"
.ColumnWidths = "150 pt;400 pt"
.Font.Size = 14
.MatchEntry = 2
.DropDown
End With
End Sub
 
Web KT

Bài viết mới nhất

Back
Top Bottom