emgaingayngo
Thành viên hoạt động
- Tham gia
- 9/2/07
- Bài viết
- 141
- Được thích
- 5
GPE cho em hỏi có cách nào rút gọn code sau:
PHP:
Sub TaoName()MotxMot
Dim the As String
S02.Activate
the = Range("The").Value
Range("L3").Select
If the = "TTMotxMot" Then ' MotxMot ->MotxChin
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[12])+COUNTIF(Table2So,R[1]C[11])+COUNTIF(Table2So,R[1]C[12])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[23])+COUNTIF(Data2So,R[1]C[22])+COUNTIF(Data2So,R[1]C[23])>=1,RC[22],""""))"
ElseIf the = "TTMotxHai" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[13])+COUNTIF(Table2So,R[1]C[11])+COUNTIF(Table2So,R[1]C[13])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[24])+COUNTIF(Data2So,R[1]C[22])+COUNTIF(Data2So,R[1]C[24])>=1,RC[22],""""))"
ElseIf the = "TTMotxBa" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[14])+COUNTIF(Table2So,R[1]C[11])+COUNTIF(Table2So,R[1]C[14])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[25])+COUNTIF(Data2So,R[1]C[22])+COUNTIF(Data2So,R[1]C[25])>=1,RC[22],""""))"
ElseIf the = "TTMotxBon" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[15])+COUNTIF(Table2So,R[1]C[11])+COUNTIF(Table2So,R[1]C[15])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[26])+COUNTIF(Data2So,R[1]C[22])+COUNTIF(Data2So,R[1]C[26])>=1,RC[22],""""))"
ElseIf the = "TTMotxNam" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[16])+COUNTIF(Table2So,R[1]C[11])+COUNTIF(Table2So,R[1]C[16])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[27])+COUNTIF(Data2So,R[1]C[22])+COUNTIF(Data2So,R[1]C[27])>=1,RC[22],""""))"
ElseIf the = "TTMotxSau" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[17])+COUNTIF(Table2So,R[1]C[11])+COUNTIF(Table2So,R[1]C[17])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[28])+COUNTIF(Data2So,R[1]C[22])+COUNTIF(Data2So,R[1]C[28])>=1,RC[22],""""))"
ElseIf the = "TTMotxBay" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[18])+COUNTIF(Table2So,R[1]C[11])+COUNTIF(Table2So,R[1]C[18])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[29])+COUNTIF(Data2So,R[1]C[22])+COUNTIF(Data2So,R[1]C[29])>=1,RC[22],""""))"
ElseIf the = "TTMotxTam" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[19])+COUNTIF(Table2So,R[1]C[11])+COUNTIF(Table2So,R[1]C[19])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[30])+COUNTIF(Data2So,R[1]C[22])+COUNTIF(Data2So,R[1]C[30])>=1,RC[22],""""))"
ElseIf the = "TTMotxChin" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[20])+COUNTIF(Table2So,R[1]C[11])+COUNTIF(Table2So,R[1]C[20])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[31])+COUNTIF(Data2So,R[1]C[22])+COUNTIF(Data2So,R[1]C[31])>=1,RC[22],""""))"
ElseIf the = "TTHaixMot" Then 'HaixMot
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[12])+COUNTIF(Table2So,R[2]C[11])+COUNTIF(Table2So,R[2]C[12])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[23])+COUNTIF(Data2So,R[2]C[22])+COUNTIF(Data2So,R[2]C[23])>=1,RC[22],""""))"
ElseIf the = "TTHaixHai" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[13])+COUNTIF(Table2So,R[2]C[11])+COUNTIF(Table2So,R[2]C[13])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[24])+COUNTIF(Data2So,R[2]C[22])+COUNTIF(Data2So,R[2]C[24])>=1,RC[22],""""))"
ElseIf the = "TTHaixBa" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[14])+COUNTIF(Table2So,R[2]C[11])+COUNTIF(Table2So,R[2]C[14])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[25])+COUNTIF(Data2So,R[2]C[22])+COUNTIF(Data2So,R[2]C[25])>=1,RC[22],""""))"
ElseIf the = "TTHaixBon" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[15])+COUNTIF(Table2So,R[2]C[11])+COUNTIF(Table2So,R[2]C[15])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[26])+COUNTIF(Data2So,R[2]C[22])+COUNTIF(Data2So,R[2]C[26])>=1,RC[22],""""))"
ElseIf the = "TTHaixNam" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[16])+COUNTIF(Table2So,R[2]C[11])+COUNTIF(Table2So,R[2]C[16])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[27])+COUNTIF(Data2So,R[2]C[22])+COUNTIF(Data2So,R[2]C[27])>=1,RC[22],""""))"
ElseIf the = "TTHaixSau" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[17])+COUNTIF(Table2So,R[2]C[11])+COUNTIF(Table2So,R[2]C[17])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[28])+COUNTIF(Data2So,R[2]C[22])+COUNTIF(Data2So,R[2]C[28])>=1,RC[22],""""))"
ElseIf the = "TTHaixBay" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[18])+COUNTIF(Table2So,R[2]C[11])+COUNTIF(Table2So,R[2]C[18])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[29])+COUNTIF(Data2So,R[2]C[22])+COUNTIF(Data2So,R[2]C[29])>=1,RC[22],""""))"
ElseIf the = "TTHaixTam" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[19])+COUNTIF(Table2So,R[2]C[11])+COUNTIF(Table2So,R[2]C[19])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[30])+COUNTIF(Data2So,R[2]C[22])+COUNTIF(Data2So,R[2]C[30])>=1,RC[22],""""))"
ElseIf the = "TTHaixChin" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[20])+COUNTIF(Table2So,R[2]C[11])+COUNTIF(Table2So,R[2]C[20])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[31])+COUNTIF(Data2So,R[2]C[22])+COUNTIF(Data2So,R[2]C[31])>=1,RC[22],""""))"
ElseIf the = "TTBaxMot" Then 'BaxMot
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[12])+COUNTIF(Table2So,R[3]C[11])+COUNTIF(Table2So,R[3]C[12])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[23])+COUNTIF(Data2So,R[3]C[22])+COUNTIF(Data2So,R[3]C[23])>=1,RC[22],""""))"
ElseIf the = "TTBaxHai" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[13])+COUNTIF(Table2So,R[3]C[11])+COUNTIF(Table2So,R[3]C[13])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[24])+COUNTIF(Data2So,R[3]C[22])+COUNTIF(Data2So,R[3]C[24])>=1,RC[22],""""))"
ElseIf the = "TTBaxBa" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[14])+COUNTIF(Table2So,R[3]C[11])+COUNTIF(Table2So,R[3]C[14])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[25])+COUNTIF(Data2So,R[3]C[22])+COUNTIF(Data2So,R[3]C[25])>=1,RC[22],""""))"
ElseIf the = "TTBaxBon" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[15])+COUNTIF(Table2So,R[3]C[11])+COUNTIF(Table2So,R[3]C[15])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[26])+COUNTIF(Data2So,R[3]C[22])+COUNTIF(Data2So,R[3]C[26])>=1,RC[22],""""))"
ElseIf the = "TTBaxNam" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[16])+COUNTIF(Table2So,R[3]C[11])+COUNTIF(Table2So,R[3]C[16])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[27])+COUNTIF(Data2So,R[3]C[22])+COUNTIF(Data2So,R[3]C[27])>=1,RC[22],""""))"
ElseIf the = "TTBaxSau" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[17])+COUNTIF(Table2So,R[3]C[11])+COUNTIF(Table2So,R[3]C[17])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[28])+COUNTIF(Data2So,R[3]C[22])+COUNTIF(Data2So,R[3]C[28])>=1,RC[22],""""))"
ElseIf the = "TTBaxBay" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[18])+COUNTIF(Table2So,R[3]C[11])+COUNTIF(Table2So,R[3]C[18])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[29])+COUNTIF(Data2So,R[3]C[22])+COUNTIF(Data2So,R[3]C[29])>=1,RC[22],""""))"
ElseIf the = "TTBaxTam" Then
ActiveWorkbook.Names.Add _
Name:="ChuaXhTT", RefersTo:="=IF(RC[11]="""","""",IF(COUNTIF(Table2So,RC[11])+COUNTIF(Table2So,RC[19])+COUNTIF(Table2So,R[3]C[11])+COUNTIF(Table2So,R[3]C[19])>=1,"""",RC[11]))"
ActiveWorkbook.Names.Add _
Name:="XhInDayTT", RefersTo:="=IF(RC[22]="""","""",IF(COUNTIF(Data2So,RC[22])+COUNTIF(Data2So,RC[30])+COUNTIF(Data2So,R[3]C[22])+COUNTIF(Data2So,R[3]C[30])>=1,RC[22],""""))"
ElseIf the = "TTBaxChin" Then
.........
End If
End Sub