Lấy giá trị ComboBox làm tên Sheets để tham chiếu

Liên hệ QC

vova2209

Thành viên tích cực
Tham gia
5/4/17
Bài viết
835
Được thích
112
Giới tính
Nam
Nghề nghiệp
Đường bộ
Mã:
Private Sub OkInBB_CDKL_Click()
    Dim inStart, inFinish As Long 'Dùng Inputbox dôi? Integer
    Dim i As Long
    Dim shNameKL, shNameCD As String
    Dim Rng As Range, DK As Long

    Set Rng = Sheets("VoVa").Range("A3", Sheets("VoVa").Range("A65535").End(xlUp)).Resize(, 4)
        inStart = TextBox1.Value
        inFinish = TextBox2.Value
        For i = inStart To inFinish
        DK = Application.WorksheetFunction.VLookup(i, Rng, 4, False)
        If DK > 0 Then GoTo Tiep
            Sheets("BBan").Range("AZ1").Value = i
            Sheets(ComboBox1).Select
            Sheets(ComboBox1).Range("AZ1").Value = i
            Sheets(shNameCD).Select
            Sheets(shNameCD).Range("AZ1").Value = i
        Next i
    Unload Me
End Sub
Chào anh chị! em có muốn hỏi ComboBox1, ComboBox2 chọn tên ở form.
Muốn duyệt ComboBox1 thành tên sheets phải sửa như nào.
Sheets(ComboBox1).Select
Sheets(ComboBox1).Range("AZ1").Value = i

. Em xin cảm ơn

Untitled.png
 
đọ code của bạn có mấy chổ mình không hiểu babj chỉ với:
1.: If DK > 0 Then GoTo Tiep : Tiep này đến đâu vậy
2. Sheets(shNameCD).Select : sheet này mình lấy ở đâu
Mã:
Private Sub OkInBB_CDKL_Click()
    Dim inStart, inFinish As Long 'Dùng Inputbox dôi? Integer
    Dim i As Long
    Dim shNameKL, shNameCD As String
    Dim Rng As Range, DK As Long
    
  If ActiveSheet.CodeName = "Sheet22" Then
    On Error Resume Next
    Set Rng = Sheets("VoVa").Range("A3", Sheets("VoVa").Range("A65535").End(xlUp)).Resize(, 4)
        inStart = TextBox1.Value 'Nêu'ko dùng form > inStart = Application.InputBox("In Tu Biên Ban:")
        inFinish = TextBox2.Value '                  inFinish = Application.InputBox("In Dên' Biên Ban:")
            shNameKL = Sheets("BBan").Range("C1") 'Duyêt sheets lây' tên o? ô cel
            shNameCD = Sheets("BBan").Range("H1")
            
        For i = inStart To inFinish
        DK = Application.WorksheetFunction.VLookup(i, Rng, 4, False)
        If DK > 0 Then GoTo tiep
            Sheets("BBan").Range("AZ1").Value = i
            Sheets("BBan").PrintOut
            
            Sheets(shNameKL).Select
            Sheets(shNameKL).Range("AZ1").Value = i
                Call HidedongProKL
            Sheets(shNameKL).PrintOut
            
            Sheets(shNameCD).Select
            Sheets(shNameCD).Range("AZ1").Value = i
                Call HidedongProCD
            Sheets(shNameCD).PrintOut
tiep:
        Next i
    Unload Me
  Else
        MsgBox "Ban phai chon o* Sheet(BBan)", vbCritical, "In Biên Ban"
  End If
Sheet22.Select
End Sub
Tên sheets đặt ở ô C1: shNameKL = Sheets("BBan").Range("C1"). Giá trị này hay tên sheets đặt ở ô excell C1 có thể thay đổi tên thành sheets khác
 
Upvote 0
Web KT

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

Back
Top Bottom