tukut3boyhp9x
Thành viên mới
- Tham gia
- 9/1/18
- Bài viết
- 16
- Được thích
- 1
- Giới tính
- Nam
Code em viết đây ạ sau khi chạy đến lặp lần 2 thì bị vấn đề như nay ạ
Em đã cố thử dùng cách redim ma không được ạ
đây la bị sao vậy ạ
Em đã cố thử dùng cách redim ma không được ạ
đây la bị sao vậy ạ
Mã:
Sub Perm()
Dim chuoi1 As Variant
Dim dk1 As Variant
Dim vitria As Integer
Dim chuoia As Variant
Dim s1 As Variant
Dim dk As Variant
Dim s2 As Variant
Dim s3 As Variant
Dim s4 As Variant
Dim s1a As Variant
Dim s2a As Variant
Dim s3a As Variant
Dim s4a As Variant
Dim dem As Long
Dim demsodong As Long
Dim sodong As Integer
Dim sokq As Integer
Dim giai As Integer
sodong = InputBox("Bac dien tong so dong bac muon thuc hien", "So dong thuc hien", "100")
sokq = InputBox("Bac muon chuyen tu bo 4(so) hay bo 5(so)", "Bo so bao nhieu?", "4")
giai = InputBox("Nhap so giai bac muon choi (45 hoac 55)", "Giai tham gia", "45")
dem = 1
vitria = 2
Range("h1:K4").EntireColumn.Insert
Range("A1:b1").EntireColumn.Insert
If giai = 55 Then
chuoi1 = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55)
End If
If giai = 45 Then
s1 = Range("C4:C104").Value
s2 = Range("D4:D104").Value
s3 = Range("E4:E104").Value
s4 = Range("F4:F104").Value
Range("A1").Value = "a"
Range("B1").Value = "b"
Range("G2").Clear 'don o a
chuoi1 = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45)
Range("B2").Value = "=COUNTIF(A2,$C$2)+COUNTIF(A2,$D$2)+COUNTIF(A2,$E$2)+COUNTIF(A2,$F$2)+COUNTIF(A2,$G$2)"
Range("A2:A46").Value = Application.WorksheetFunction.Transpose(chuoi1)
Range("B2:B46").FillDown
For Each s1a In s1
For Each s2a In s2
For Each s3a In s3
For Each s4a In s4
Range("F2").Value = s4a
Range("E2").Value = s3a
Range("D2").Value = s2a
Range("C2").Value = s1a
Range("$B$1:$B$46").AutoFilter Field:=1, Criteria1:="0"
Range("A2:A46").Copy
Range("A47").Select
ActiveSheet.Paste
Columns("B:B").AutoFilter
dk = Range("A47:A86").Value
Range("A47:A87").Clear
For Each chuoia In dk
dem = dem + 1
Range("$G$2") = chuoia
Range("$B$1:$B$46").AutoFilter Field:=1, Criteria1:="0"
Range("A2:A46").Copy
Range("A47").Select
ActiveSheet.Paste
Columns("B:B").AutoFilter
dk1 = Range("A47:A86").Value
Range("A47:A86").Clear
'dua ra ket qua
Range(Cells(vitria, 10), Cells(vitria + 39, 10)).Value = s1a
Range(Cells(vitria, 11), Cells(vitria + 39, 11)).Value = s2a
Range(Cells(vitria, 12), Cells(vitria + 39, 12)).Value = s3a
Range(Cells(vitria, 13), Cells(vitria + 39, 13)).Value = s4a
Range(Cells(vitria, 14), Cells(vitria + 39, 14)).Value = chuoia
Range(Cells(vitria, 15), Cells(vitria + 39, 15)).Value = dk1
vitria = vitria + 40
If dem = 42 Then
demsodong = demsodong + 1
Range("I1").EntireColumn.Insert
dem = 1
vitria = 2
If demsodong = sodong + 1 Then
Range("A1").EntireColumn.Delete
Range("A1").EntireColumn.Delete
GoTo ketthuc
End If
GoTo dongmoi
End If
Next chuoia
Next s4a
Next s3a
Next s2a
dongmoi: Next s1a
End If
ketthuc: End Sub