miércoles, 2 de mayo de 2012

Realizar un formulario :)

Private Sub CommandButton1_Click()
Sheets("Captura").Select
[A2] = Val(TextBox1)
[B2] = TextBox2
[C2] = TextBox3
[D2] = Val(TextBox4)
[E2] = Val(TextBox5)
'calculo de sueldo total
TextBox6 = Val(TextBox4) + Val(TextBox5)
'calculo de IGSS
TextBox7 = Val(TextBox4) * 0.0483

'calculo de liquidacion
TextBox8 = Val(TextBox6) - Val(TextBox7)
Range("A2:E2").Select
    Selection.Copy
    Sheets("Base_Datos").Select
    Range("A2:E2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("E2").Select
    Application.CutCopyMode = False
    Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
    Sheets("Captura").Select
    Range("A2:E2").Select
    Selection.ClearContents
    Range("A2").Select






End Sub

miércoles, 25 de abril de 2012

Formularios con celdas inactivas

Procedimiento
Primeramente se le pondra nombre a las hojas.
la primera hoja se llamara CAPTURA y la otra BASE_DATOS
Presionamos Alt+f11
nos aparecera la vista de Visual Basic
Insertamos un Userform
colocamos CODIGO, NOMBRE, CARGO Y SUELDO IGSS Y EL LIQUIDO
EN EL BOTON SE COLOCARA LOS SIGUIENTES CODIGOS
textbox1=A1
textbox2=b1
textbox3=c1
textbox4=d1
textbox5=e1
textbox6= val(textbox4) *0.0483
Textbox7= val(texbox4) - val(textbox6)

Colorear celdas Excel al hacer click



vbaproyecto
Este trocito de código VBA Excel colorear celdas al hacer click sobre ellos. Es una macro que utiliza el evento Worksheet_SelectionChange de las hojas de libro Excel.


Por eso hay que incluir este código en los objetos de las hojas. En ejemplo abajo habría que poner el código en los contenedores de código de una o mas de los objetos Hoja1, Hoja2 y Hoja3.

Para colorear solo la celda activa

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveCell.Interior.ColorIndex = 3
End Sub

Para colorear todas las celdas seleccionadas

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Target.Interior.ColorIndex = 3
End Sub

miércoles, 28 de marzo de 2012

Cambio de Color y estructura con un Boton de Visual Basic

Ahora utilizaremos de forma sencilla un boton de formulario en conjunto con macros grabadas.
Primero grabaremos una macro, en la hoja pondremos un formato decorado:

Ahora teniendo la primera macro grabada, grabaremos la segunda macro, le cambiaremos la estructura el color y el sombreado etc.

Por ultimo crearemos la tercera macro, a esta tambien le cambiaremos la fuente el color el sombreado y el fondo.

Pondremos unos indicadores:

Ahora nos vamos a la opcion programador, elegimos insertar y por ulitmo insertar boton de formulario.


Ahora ya teniendo el boton le damos doble clic, he ingresamos a Visual Basic y creamos un modulo.
Utilizaremos el condicional IF
Sub estilo()
If [d2] = 1 Then
 Range("A9:E9").Select
    Selection.Font.Size = 12
    Selection.Font.Size = 14
    Selection.Font.Size = 16
    Selection.Font.Size = 18
    Selection.Font.Size = 20
    Selection.Font.Size = 22
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent2
        .TintAndShade = 0.399975585192419
        .PatternTintAndShade = 0
    End With
    Selection.Font.Bold = True
    With Selection.Font
        .Name = "Aharoni"
        .Size = 22
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With
    Range("A10:A16").Select
    Selection.Font.Size = 12
    Selection.Font.Size = 14
    Selection.Font.Size = 16
    Selection.Font.Size = 18
    Selection.Font.Size = 16
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorLight2
        .TintAndShade = 0.799981688894314
        .PatternTintAndShade = 0
    End With
    Range("A10:A16").Select
    Selection.Font.Bold = True
    Range("B10:E16").Select
    With Selection.Font
        .Name = "Adobe Hebrew"
        .Size = 11
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = -0.499984740745262
        .PatternTintAndShade = 0
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.399975585192419
        .PatternTintAndShade = 0
    End With
    Range("B10:E16").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Range("B10").Select
        End If
       
    If [d2] = 2 Then
    Range("A9:E9").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent1
        .TintAndShade = 0.399975585192419
        .PatternTintAndShade = 0
    End With
    Selection.Font.Size = 24
    Selection.Font.Size = 26
    Selection.Font.Size = 24
    Selection.Font.Size = 22
    Selection.Font.Size = 20
    Selection.Font.Size = 18
    Selection.Font.Italic = True
    With Selection.Font
        .Name = "Hobo Std"
        .Size = 18
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With
    Range("A10:A16").Select
    Selection.Font.Bold = False
    Selection.Font.Italic = True
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark2
        .TintAndShade = -0.249977111117893
        .PatternTintAndShade = 0
    End With
    Range("B10:E16").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent5
        .TintAndShade = 0.399975585192419
        .PatternTintAndShade = 0
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Range("B9:E9").Select
    Selection.Font.Size = 16
    Selection.Font.Size = 14
    Range("G14").Select
    ActiveWindow.SmallScroll Down:=-15
    End If
    If [d2] = 3 Then
     Range("A9:E9").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Range("A10:A16").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark2
        .TintAndShade = -0.899990844447157
        .PatternTintAndShade = 0
    End With
    With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    With Selection.Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    Range("B10:E16").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark2
        .TintAndShade = -0.899990844447157
        .PatternTintAndShade = 0
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent3
        .TintAndShade = 0.399975585192419
        .PatternTintAndShade = 0
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent2
        .TintAndShade = 0.399975585192419
        .PatternTintAndShade = 0
    End With
    Range("A10:A16").Select
    With Selection.Font
        .Name = "Comic Sans MS"
        .Size = 16
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With
    Columns("A:A").ColumnWidth = 16.57
    Range("G15").Select
    Columns("B:B").ColumnWidth = 14.71
    Columns("C:C").ColumnWidth = 12.71
    Columns("D:D").ColumnWidth = 13.71
    Columns("E:E").ColumnWidth = 18.14
    Columns("E:E").ColumnWidth = 14.86
    End If
   
End Sub



 Y por ultimo copiamos las macros













martes, 27 de marzo de 2012

Sistema de Facturación utilizando Visual Basic

primeramente explicaremos que el sistema de facturación lo realizaremos utilizando las formulas antes vistas "=BUSCARV( )" "=INIDICE( )" entre otras.
Primero haremos el formato de la factura

Ahora añadiremos las formulas:




Y sobretodo muy importante! crear una base de datos, y esta se llamara Productos

Ahora ya teniendo el libro con el sistema de facturación crearemos el sistema de cotización






AHORA CREAREMOS LAS VENTANAS CON LA AYUDA DE USERFORM




miércoles, 29 de febrero de 2012

SISTEMA DE ASISTENCIA

  1. Primero crearemos una base de datos, esta estara conformada por, CODIGO, NOMBRE, GRADO Y CARRERA

2. Ahora ya creada la base de datos, nos dirijiremos a la hoja 1, ahi pondremos CODIGO, NOMBRE, GRADO, CARRERA, HORA, FECHA Y CODIGO nuevamente.


3. Ahora nos ubicamos en la fila 20 y copiamos los mismos datos que la fila anterior.
4. Ahora, nos dirigimos nuevamente a la fila 1, y empezamos a colocar y a utilizar las formulas aprendidas anteriormente(=BUSCARV(), =SI( ), =HOY( ), =AHORA( ) ETC)

A) CODIGO: =VAL(G2)

B) Ahora en la celda del nombre, buscaremos la informacion la base de datos anterior, la matriz de llama "DATOS".

 C) Ahora utilizaremos la misma formula para buscar valor solo variando numero de fila.

D)  Se utiliza la misma formula en CARRERA, variando siempre el numero de fina de la matriz

E) En la fecha se va a utilizar la formula =AHORA()

F) La formula para la fecha es =HOY( )
G) Ahora en la celda G2 ingresaremos algun codigo de la base de datos

Formato de asistencia

La asistencia en un establecimiento es muy importante, y que mejor que hacerlo de una manera practica, sistematica y exacta.
Entonces aqui podemos poner nuestros concocimentos de visual basic en practica.
Crearemos un sistema de asistencia utilizando lo que hemos aprendido sobre Visual Basic,
es un reto pero nada es imposible!!!!

Codigos que se pueden utilizar en excel

  • Pegar:
Avtivesheet.paste

  •  
formato asistencia

lunes, 27 de febrero de 2012

VISTA DE NUESTRO FORMULARIO EJEMPLO #1


Ejemplo de FOrmulariO

Crearemos ahora ahora un formulario donde solo llenándolo forme una base de datos que se corra por si misma.

  • Primero haremos nuestro esquema:
  • Ahora presionaremos ATL+F11
  • Ahora damos clic en la opción insertar USEFORM
  • Ahora llenamos con NOMBRE, SUELDO, HORAS_EXTRAS, NO. DE HORAS Y BONIFICACION Y LE PONEMOS UN BOTÓN
  • Ahora damos doble clic al botón, y escribimos los criterios y coman dos
Private Sub CommandButton1_Click()
[A2] = TextBox1
[b2] = TextBox2
[c2] = TextBox5
[E2] = TextBox3
[g2] = TextBox4


[d2] = Val([E2]) / 30 / 8 * Val([g2])
[f2] = Val([E2]) * 0.0483
[h2] = Val([E2]) + Val([d2]) - Val([f2])

Range("a2").Select
Selection.EntireRow.Insert
Range("a3").Select

TextBox1 = Empty
TextBox2 = Empty
TextBox5 = Empty
TextBox3 = Empty
 TextBox1.SetFocus
End Sub


Y por ultimo le damos clic en EJECUTAR



¿Que es un Formulario en VB?

Un formaulario es una ventana, es donde se dibujaran los controles que utilizes. cajas de texto, labels, imagenes todo!

Vista previa de nuestra macro creada:


Formula para sumar dos valores desde la macros anterior


[e2] = Val([D2]) + Val([c2])
[e3] = Val([D3]) + Val([c3])
[e4] = Val([D4]) + Val([c4])
[e5] = Val([D5]) + Val([c5])
[e6] = Val([D6]) + Val([c6])

Ejercicio

Bien ahora que ya sabemos como hacer un modulo, crearemos un ejercicio donde este NO, SUELDO, NOMBRE, BONO Y SUELDO TOTAL

Presionamos ATL+F11
y colocamos los siguientes comando:


Nuestra macros habrá quedado así:


FORMULA PARA PONER NEGRITA

La formula para poner negrita es:


Selection.Font.Bold = True

CREAR UNA MACRO DESDE VISUAL BASIC

Visual Basic es un lenguaje de programación dirigido por eventos, desarrollado por el alemán Alan Cooper para Microsoft. Este lenguaje de programación es un dialecto de BASIC, con importantes agregados. Su primera versión fue presentada en 1991, con la intención de simplificar la programación utilizando un ambiente de desarrollo completamente gráfico que facilitara la creación de interfaces gráficas y, en cierta medida, también la programación misma.

Ahora bien crearemos una macro en visual basic

  • presionamos ATL+f11
Ahi saldra la hoja de visual basic, insertamos un modulo
escribimos nuestros codigos:
Nota: RANGE("").select indican que numero de celda es en la que se esta trabajando.
y ACTIVECELL.FORMULAR1C1, es para poder escribir en la celda.
SE EMPIEZA ESCRIBIENDO "SUB" Y SE FINALIZA ESCRIBIENDO "END SUB"