You are on page 1of 4

Option Explicit Function RangeNameExists(Nname) As Boolean ' Kiem tra xem ten co ton tai hay khong '

Neu ton tai thi tra ve R!E "im n As Name RangeNameExists # False For Each n $n Active%ork&ook'Names $( !)ase(n'Name) # !)ase(Nname) hen RangeNameExists # rue Exit Function En* $( Next n En* Function +u& "atten(By,al ensheet As +tring- By,al en&ang As +tring- By,al R. As $ntegerBy,al ). As $nteger- By,al R/ As $nteger- By,al )/ As $nteger) ' hu tuc nay nham *at ten cho &ang *u lieu "im &)ongthuc On Error Resume Next &)ongthuc # 0#0 1 ensheet 1 02R0 1 R. 1 0)0 1 ). 1 030 1 0R0 1 R/ 1 0)0 1 )/ Active%ork&ook'Names'A** Name3# en&ang- Re(ers oR.).3#&)ongthuc En* +u& +u& Nhap"u4ieu() On Error Resume Next )all "ata+elector(05a,at u0) En* +u& +u& "ata+elector( en&ang As +tring) "im &5ang. On Error Resume Next &5ang. # a&le oArray( en&ang) )all Array o4istvie6((rm"ata+elector'4,"ata+elector- &5ang.) (rm"ata+elector'+ho6 En* +u& ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ')huyen tu mang 7ua 4istvie6 khong co itle ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +u& Array o4istvie6(By,al ,list,ie6 As 4istvie6- By,al $nputArray) "im m As 4ong "im i As $nteger- 8 As $nteger "im &9ang As 4ong- &)ot As 4ong- &9ea*er As $nteger "im it As 4ist$tem "im an$tem $( Not $sO&8ect(,list,ie6) hen Exit +u&

'On Error Resume Next '"em so hang va so cot trong $nputArray &9ang # !Boun*($nputArray- .) &)ot # !Boun*($nputArray- /) '"inh *ang 4ist,ie6 ,list,ie6',ie6 # lv6Report ,list,ie6'FullRo6+elect # rue ,list,ie6'5ulti+elect # False ,list,ie6':ri*lines # rue ,list,ie6'4a&elE*it # lv65anual ,list,ie6'9i*e)olumn9ea*ers # rue &9ea*er # ,list,ie6')olumn9ea*ers'count +elect )ase &9ea*er )ase $s ; &)ot For i # &9ea*er < . o &)ot ,list,ie6')olumn9ea*ers'A** i Next i )ase $s # &)ot '"o nothing )ase $s = &)ot '"o nothing En* +elect '"ien cac gia tri tu $nputarray vao 4istvie6 For i # . o &9ang For 8 # . o &)ot an$tem # $nputArray(i- 8) $( 8 # . hen +et it # ,list,ie6'4ist$tems'A**() it' ext # an$tem Else it'+u&$tems(8 > .) # an$tem En* $( Next 8 Next i '"at chieu rong cua cac cot For i # . o &)ot ,list,ie6')olumn9ea*ers(i)'%i*th # .?@ Next i ':iai phong &ien +et it # Nothing Exit +u& &loi3 5sgBox 0+orry- can not loa* a Array to 4istvie6 0 1 Err'"escription- v&)ritical0%arning0

Err')lear En* +u& ' "ay la ham *e xuat cac *u lieu tu cac &ang ("a *uoc *at ten) ' sang mang ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function a&le oArray(By,al a&leName As +tring) "im arr "im vRange As Range "im i As 4ong- 8 As 4ong- m As 4ong- n As 4ong $( Not RangeNameExists( a&leName) hen Exit Function On Error Resume Next +et vRange # Range( a&leName) i # vRange'Ro6s'count 8 # vRange')olumns'count Re"im arr(. o i- . o 8) For m # . o i For n # . o 8 arr(m- n) # vRange(m- n)',alue Next n Next m a&le oArray # arr +et vRange # Nothing En* Function

Arivate +u& cm*)ancelB)lick() !nloa* 5e En* +u& Arivate +u& cm*OKB)lick() "im &:iatrichon On Error Resume Next &:iatrichon # 4,"ata+elector'+electe*$tem' ext Active)ell',alue # &:iatrichon En* +u& Arivate +u& txt)o*eB)hange() "im it As 4ist$tem On Error Resume Next &tim # 5e'txt)o*e' ext +et it # 5e'4,"ata+elector'Fin*$tem(&tim- lv6 ext- - lv6Aartial) &in*ex # it'$n*ex 5e'4,"ata+elector'4ist$tems'$tem(&in*ex)'+electe* # rue 5e'4,"ata+elector'4ist$tems'$tem(&in*ex)'Ensure,isi&le +et it # Nothing En* +u&

C,ao sheet /

Arivate +u& %orksheetBBe(oreRight)lick(By,al target As Range- )ancel As Boolean) $( target')olumn # . hen )ancel # rue )all Nhap"u4ieu En* $( En* +u& Arivate +u& %orksheetBselectionchange(By,al target As Range) "im i As $nteger $( target'Ro6 # i hen For i # / o ?@@ $( )ells(i- .) ;= 00 hen )ells(i > .- /)'+elect +election')opy )ells(i- /)'+elect Active+heet'Aaste En* $( Next En* $( Application'+creen!p*ating # False En* +u&