Sei sulla pagina 1di 12

SELECCIONA FINAL DE LA CELDA ACTIVA, ABAJO, IZQUIERDA, DERECHA Y ARRIBA

Activecell.end(xldown)
Activecell end(xltoleft)
Activecell end(xltoright)
Activecell end(xlup)
SELECCIONA LA LINEA SIGUIENTE
Activecell.offset(1,0).select
PARA RECORRER UN RANGO ESTABLECIDO POR EL USUARIO A TRAVES DE
REFEDIT
Dim <variable As !ange
"et <variable # !ange(!efedit.value)
SELECCIONA UNA CELDA O RANGO DE CELDAS
!ange($A1%&'()."elect
!ange($&)().Activate
AGREGAR NUEVA HOJA Y ESTABLECE NOMBRE DE LA HOJA
Dim *ueva+o,a as -b,eto
"et *ueva+o,a # .or/sheets.Add
*ueva+o,a.*ame # $0resupuesto(
GRABAR ARCHIVO
Active..or/boo/."ave
SOLICITAR UN RANGO A TRAVES DE INPUTBOX
Dim 1i!ango as !ange
"et 1i!ango # Application.inputbox(0rompt.%#("eleccione un !ango para 2raspaso(
VERIFICA QUE EL RANGO SELECCIONADO SEA DE LA COLUMNA A
3f 1irando.column < 1 2hen
1sgbox $4l !ango "eleccionado *- es 5alido(, 5b6ritical
4xit "ub
4nd if
PONE NOMBRE DE RANGO A CELDA ACTIVA
BAJA 5 LINEAS, COLOCA HOLA, VUELVE A CELDA NOMBRE Y ELIMINA
NOMBRE
Active6ell.*ame # $*ombre(
Active6ell.-ffset(7,0).Activate
Active6ell.5alue # $+ola(
Application.8oto!eference%# $*ombre(
Active.or/boo/.*ames($*ombre().Delete
SELECCIONAR HOJA DENTRO DEL LIBRO
"heets($*ombre()."elect
BORRAR CONTENIDO DE LA CELDA
"election.6lear6ontents
SELECCIONAR TODA LA HOJA
6ells."elect
ELIMINA COLUMNA, FILA, CELDA
"election.4ntire6olumn.Delete
"election.4ntire!ow.Delete
"election.Delete shift %# xlup
INSERTAR COLUMNA, FILA, CELDA
"election.4ntirecolumn.3nsert
"election.4ntire!ow.3nsert
"election.3nsert shift %# 9lDown
ACTIVAR UN ARCHIVO ABIERTO
.indows ($*ombreArchivo().Activate
SOLICITA UNO O VARIOS RANGOS DEL MISMO LIBRO U OTROS LIBROS ABIERTOS Y
PROCESAR EL RANGO SELECIONADO
Dim 1i6elda, 1i0roc as !ange
"et 1i6elda # Application.3put&ox(prompt%#(3ngrese !ango $,2:pe%#;)
<or 4ach 1i0roc 3n 1i6elda
=instrucciones>
*ext
SELECCIONA UNA CARPETA DE UN LIBRO ABIERTO
.or/sheets($nombre carpeta().Activate
SELECCIONA UN RANGO
!ange($nombre rango().Activate
INSERTA UNA LINEA SI LA FILA SIGUIENTE CUMPLE LA CONDICION
3f Active6ell.-ffset(1,0).5alue#(contenido celda( then Active6ell.4ntire!ow.3nsert
IR AL FINAL DE LA SELECCION Y POSESIONARSE EN LA LINEA SIGUIENTE
Active6ell.4nd(xlDown)."elect
INSERTA LINEA SI DOS FILAS MAS ABAJO DE CELDA ACTIVA TIENE DATOS
3f Active6ell.-ffset(),0)<(( then
"election.4ntire!ow.3nsert
4nd if
INGESA DATOS DE UN LISTVIEW A LA PLANILLA EXCEL
Dim a as 3nteger
<or a# 1 to =nombre userform>.=nombre listview>.?ist3tem.6ount
Active6ell.-ffset(0,@).5alue# =nombre userform>.=nombre listview>.?ist3tem(a)."ub3tem())
*ext a
()) corresponde a columna del ?istview a traspasar, numero variable
PONE UNA FORMULA EN LA CELDA ACTIVA
Active6ell.-ffset(0, 1)).<ormula!161 # A#r=B1>cCrc=B)>Brc=B1>A
0one la formula a 1) columnas de la posiciDn actual
Active6ell.<ormula!161 # (A#subtotal(E,rFc1'%r10000c1')A)
0one la formula en la celda activa
PONE UNA FORMULA A PARTIR DE LA CELDA ACTIVA 5 COLUMNAS A LA DERECHA
(SUMA HACIA ARRIBA
Dim fila as string
fila # A#"G1(r=BA H Active6ell.!ow B @ H A>c%r=B1>c)A
Active6ell.-ffset(0, 7).<ormula!161 # fila
CAPTURA LA SELECCI!N ACTUAL Y LA TRANSFORMA EN
UN RANGO PARA TRABAJAR CELDA A CELDA
0ublic "ub 0ositivo*egativo()
Dim !s As "tring
Dim !g As !ange
!s # Active.indow.!ange"election.Address(<alse, <alse)
<or 4ach !g 3n !ange(!s)
3f !g.5alue 0 2hen
!g.5alue # !g.5alue I B1
4nd 3f
*ext
4nd "ub
"DESPLIEGA TODOS LOS NOMBRES DE LAS HOJAS QUE CONTIENE EL LIBRO
"ub *ombrede+o,as()
Dim celda As 3nteger
Dim +o,a As .or/sheet
celda # 1
<or 4ach +o,a 3n .or/sheets
"heets(1).6ells(celda, 1).5alue # +o,a.*ame
celda # celda C 1
*ext +o,a
4nd "ub
SUMA COLUMNAS # A $ QUE ESTAN A LA DERECHA DE LA CELDA ACTIVA
Y ELIMINA LA LINEA QUE SU SUMA ES CERO
0ublic "ub "uma6ero()
Dim " As Double
Dim i As 3nteger
Do .hile Active6ell.5alue < AA
" # 0
<or i # ) 2o E
" # " C Active6ell.-ffset(0, i).5alue
*ext i
3f " # 0 2hen
"election.4ntire!ow.Delete
4lse
Active6ell.-ffset(1, 0).Activate
4nd 3f
?oop
4nd "ub
REDONDEAR CELDAS
J!edondea el contenido numerico de la celda a cero decimal
Dim !r As !ange
Dim "s As !ange
Dim KL As Double

"et !r # "election
<or 4ach "s 3n !r
KL # !ound("s, 0)
"s.5alue # KL
"s.*umber<ormat # AM,MM0A
*ext "s
FORMATEAR FUENTE
6ells."elect
.ith "election.<ont
.*ame # A1" "ans "erifA
."iLe # 10
4nd .ith
L%NEAS DE DIVISI!N
Active.indow.Displa:8ridlines # <alse
INDICE DE COLORES
Active.or/boo/.6olors(NN) # !8&()'@, )'7, 1EN) Jverde
COLOREAR RANGO
!ange(AA1%&10A).3nterior.6olor3ndex # NN
CAMBIAR ENTRE ESTILOS A& ' RC
Application.!eference"t:le # xlA1Application.!eference"t:le # xl!161
P()*+,-. / 0C123 4+)53 .,+6.( )6 )7)8-3 5) 6. 4+69.8:1, 5) -)86.9 8323 )6 R)P.*, A;P.*, E98 3
9:2:6.()9 .6 -(.<.=.( 83, 73(2+6.(:39>
!espuesta % "i Ouieres anular la pulsaciDn de alguna tecla al traba,ar con formularios, primero debes ir a
la ventana de propiedades del formulario : poner la propiedad 2ecla de vista previa (Pe:0review) a "Q.
De esta manera, se fuerLa a Oue el formulario sea el primero en detectar la pulsaciDn de cualOuier tecla,
antes de Oue lo haga el control activo en ese momento, Oue, de otra manera, serQa el primero en
hacerlo. DespuRs deberemos utiliLar algSn tipo de cDdigo para detectar la pulsaciDn de la tecla en el
evento Al ba,ar una tecla (Pe:Down) : anularla. 4ste evento detecta prTcticamente todas las
pulsaciones de teclas, en detrimento del evento Al presionar una tecla (Pe:0ress) Oue sDlo detecta las
teclas tQpicas de la escritura como son los caracteres alfanumRricos : los sQmbolos utiliLados en los
diferentes idiomas.
4n nuestro caso, podemos llamar a una funciDn genRrica Oue he construQdo : Oue servirT para anular
cualOuier tipo de tecla Oue le pasemos en su segundo parTmetro, el cual tiene un nSmero de elementos
indeterminado.
?a funciDn DeletePe:s tiene los siguientes
Argumentos
*ombre DescripciDn
Pe:6ode !eOuerido. 4l valor de la tecla pulsada : Oue estT recogida en el primer argumento del
evento Pe:Down, del mismo nombre% Pe:6ode
Pe:s -pcional. ?ista separada por comas de los valores A"633 o las constantes 5isual &asic (ver
estas constantes en este enlace ) de las teclas que se quieren anular.
4sta funciDn tambiRn puede ser utiliLada a travRs del evento Pe:Down de un control. <uncionarT de la
misma manera Oue para un formulario.
Gn e,emplo de uso%
J esta llamada a la funciDn DeletePe:s anularT la pulsaciDn de las
J teclas !e0ag : Av0ag en el evento Pe:Down de un formulario
0rivate "ub <ormUPe:Down(Pe:6ode As 3nteger, "hift As 3nteger)
6all +elpPe:s(Pe:6ode, vbPe:0ageGp, vbPe:0ageDown)
4nd "ub
0ega esta funciDn en un mDdulo estandar%
JBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
J
J DeletePe:s
J
J 6Ddigo escrito originalmente por Vuan 1 AfTn de !ibera.
J 4stTs autoriLado a utiliLarlo dentro de una aplicaciDn
J siempre Oue esta nota de autor permaneLca inalterada.
J 4n el caso de Ouerer publicarlo en una pTgina .eb,
J por favor, contactar con el autor en
J
J accessvbafaOW:a.com
J
J 4ste cDdigo se brinda por cortesQa de
J Vuan 1. AfTn de !ibera
J
<unction DeletePe:s(Pe:6ode As 3nteger, 0aramArra: Pe:s() As 5ariant) As 3nteger
Dim Pe: As 5ariant
<or 4ach Pe: 3n Pe:s
3f Pe:6ode # Pe: 2hen
Pe:6ode # 0
4xit <unction
4nd 3f
*ext

4nd <unction
Constantes de tecla Visual Basic
Constante Valor Descripcin
vbKeyLButton 1 botn izquierdo del ratn
vbKeyRButton 2 botn derecho del ratn
vbKeyCancel 3 tecla CANCEL
vbKeyMButton botn central del ratn
vbKeyBac! " tecla Retroce#o
vbKey$ab % tecla $abulador
vbKeyClear 12 tecla CLEAR
vbKeyReturn 13 tecla Enter
vbKey&hi't 1( tecla May)#cula#
vbKeyControl 1* tecla Ctrl
vbKeyMenu 1" tecla Menu
vbKey+au#e 1% tecla +au#a
vbKeyCa,ital 2- tecla Bloq May)#
vbKeyE#ca,e 2* tecla E#c
vbKey&,ace 32 tecla E#,aciador
vbKey+a.e/, 33 tecla Re+0.
vbKey+a.e1o2n 3 tecla Av+0.
vbKeyEnd 33 tecla 4in
vbKey5o6e 3( tecla 7nicio
vbKeyLe't 3* tecla 4lecha 7zquierda
vbKey/, 3" tecla 4lecha Arriba
vbKeyRi.ht 3% tecla 4lecha 1erecha
vbKey1o2n - tecla 4lecha Aba8o
vbKey&elect 1 tecla &ELEC$
vbKey+rint 2 tecla 76,r+ant
vbKeyE9ecute 3 tecla E:EC/$E
vbKey&na,#hot tecla &NA+&5;$
vbKey7n#ert 3 tecla 7n#ertar
vbKey1elete ( tecla &u,r
vbKey5el, * tecla 5EL+
vbKey- " tecla -
vbKey1 % tecla 1
vbKey2 3- tecla 2
vbKey3 31 tecla 3
vbKey 32 tecla
vbKey3 33 tecla 3
vbKey( 3 tecla (
vbKey* 33 tecla *
vbKey" 3( tecla "
vbKey% 3* tecla %
vbKeyA (3 tecla A
vbKeyB (( tecla B
vbKeyC (* tecla C
vbKey1 (" tecla 1
vbKeyE (% tecla E
vbKey4 *- tecla 4
vbKey< *1 tecla <
vbKey5 *2 tecla 5
vbKey7 *3 tecla 7
vbKey= * tecla =
vbKeyK *3 tecla K
vbKeyL *( tecla L
vbKeyM ** tecla M
vbKeyN *" tecla N
vbKey; *% tecla ;
vbKey+ "- tecla +
vbKey> "1 tecla >
vbKeyR "2 tecla R
vbKey& "3 tecla &
vbKey$ " tecla $
vbKey/ "3 tecla /
vbKey? "( tecla ?
vbKey@ "* tecla @
vbKey: "" tecla :
vbKeyA "% tecla A
vbKeyB %- tecla B
vbKeyNu6,ad- %( tecla - del teclado nu6Crico
vbKeyNu6,ad1 %* tecla 1 del teclado nu6Crico
vbKeyNu6,ad2 %" tecla 2 del teclado nu6Crico
vbKeyNu6,ad3 %% tecla 3 del teclado nu6Crico
vbKeyNu6,ad 1-- tecla del teclado nu6Crico
vbKeyNu6,ad3 1-1 tecla 3 del teclado nu6Crico
vbKeyNu6,ad( 1-2 tecla ( del teclado nu6Crico
vbKeyNu6,ad* 1-3 tecla * del teclado nu6Crico
vbKeyNu6,ad" 1- tecla " del teclado nu6Crico
vbKeyNu6,ad% 1-3 tecla % del teclado nu6Crico
vbKeyMulti,ly 1-( tecla &D6bolo Multi,licacin EFG del teclado nu6Crico
vbKeyAdd 1-* tecla &D6bolo &u6a EHG del teclado nu6Crico
vbKey&e,arator 1-" tecla 7ntro del teclado nu6Crico
vbKey&ubtract 1-% tecla &D6bolo Re#ta EIG del teclado nu6Crico
vbKey1eci6al 11- tecla &D6bolo deci6alEJG del teclado nu6Crico
vbKey1ivide 111 tecla &D6bolo 1ivi#in EKG del teclado nu6Crico
vbKey41 112 tecla 41
vbKey42 113 tecla 42
vbKey43 11 tecla 43
vbKey4 113 tecla 4
vbKey43 11( tecla 43
vbKey4( 11* tecla 4(
vbKey4* 11" tecla 4*
vbKey4" 11% tecla 4"
vbKey4% 12- tecla 4%
vbKey41- 121 tecla 41-
vbKey411 122 tecla 411
vbKey412 123 tecla 412
vbKey413 12 tecla 413
vbKey41 123 tecla 41
vbKey413 12( tecla 413
vbKey41( 12* tecla 41(
vbKeyNu6loc! 1 tecla BloqNu6
Vamos a ello. Te podra dar una API que detecta tal hecho, pero lo mejor y ms sencillo -y
por lo tanto lo ms adecuado- es emplear el evento Keyo!n. "rea un #ormulario con un
Te$t, y codi#ica lo si%uiente&
Private 'u( Te$t)*Keyo!n+Key"ode As Inte%er, 'hi#t As Inte%er,
'elect "ase Key"ode
"ase v(Key-p
.s%/o$ 0Tecla arri(a0
"ase v(Keyo!n
.s%/o$ 0Tecla a(ajo0
"ase v(Key1i%ht
.s%/o$ 0Tecla derecha0
"ase v(Key2e#t
.s%/o$ 0Tecla i3quierda0
4nd 'elect
4nd 'u(
"omom vers se trata de capturar las teclas empleando las constantes que Visual /asic
provee. -na ve3 capturadas las teclas, hacer que se mueva la ima%en o cualquier control es
(ien sencillito 4n cada 0"A'40 adiciona o resta ms a la propiedad 245T o T6P del control
en cuesti7n.
5alidacion de la fecha ingresada en un textbox
*ombre textbox # 2xt<echa6omp (o el nombre Oue se asigno al textbox)
3f *ot 3sDate(2xt<echa6omp.2ext) 2hen Jvalidacion fecha
1sg&ox A<echa 3ncorrecta XXXA, vb6ritical C vb-P-nl:, A<echa 4rroneaA
2xt<echa6omp.2ext # AA
PARA CREAR UN ARCHIVO DE TEXTO, SEPARADO POR TAB
+rint L $e9t1Jte9t M vb$ab M $e9t2J$e9t
CARGAR COMBOS CON INFORMACION Y SELECCION PARALELA
(se necesita un userform, dos combobox, un boton comando, en la planilla exel dos columnas
con datos la primera columna con nombre asignado al rango $plan( )
0rivate "ub <nombrecombo1U6hange()
<nombrecombo).?ist3ndex # <nombrecombo1.?ist3ndex
4nd "ub
0rivate "ub <nombrecombo)U6hange()
<nombrecombo1.?ist3ndex # <nombrecombo).?ist3ndex
4nd "ub
0rivate "ub 6md"alirU6lic/()
4nd
4nd "ub
0rivate "ub Gser<ormU3nitialiLe()
J6argamos los nros de cuentas con sus nombres
Dim c As !ange
<or 4ach c 3n !ange(AplanA)
<nombrecombo1.Add3tem c.5alue JAgregamos el nro de cuenta
<nombrecombo).Add3tem c.-ffset(0, 1).5alue JAgregamos el nombre de la cuenta
*ext
"et c # *othing J?impiamos el ob,eto JcJ
4nd "ub
CAPTURA EN UNA VARIABLE LA SELECCI!N DE UN COMBOBOX
<var # combo.list(combo.listindex)

Potrebbero piacerti anche