Inputbox

Hola, tengo una macro automática que al abrir la planilla, hace dos cosas
Por un lado cambio los nombres de la hojas y luego ingreso el mes y el numero de mes, el problema radica en que cuando ingreso el mes y su numero ya que si no deseo modificarlos deje el dato anterior, o bien a veces abro muchas veces el mismo libro y no quiero ingresar cada vez el mes y el numero, copio el código
Muchas gracias,

1 respuesta

Respuesta
1
Si estás solicitando el mes y nro a través de inputbox podes dejar esos valores como predeterminados, con lo que un smple enter avanzaría sin modificarlos. (Fíjate en la ayuda los argumentos del InputBox.
Si esto no resuelve tu consulta copiá el código que ya tenés para que te lo ajuste.
Elsa, muchas gracias pr tu respuesta, en este caso es un archivo mediante el cual se evalúa la gestión de algún mes en particular que generalemtne no es el mes corriente, por lo cual lo incorpore por inputbox, si bien en el caso del cambio de nombre de hoja no tengo inconvenientes ya que utilice el code.name, pero no se implementarlo para rangos, te copio el código:
Sub AUTO_OPEN()
Dim Nuevo_Nombre As String, Texto As String
Dim Hoja As Worksheet
Dim mas_datos As Integer, Valor As Integer
mas_datos = MsgBox("¿Desea modificar el nombre de la hojas? ", vbYesNo + vbQuestion, "MODIFICAR NOMBRES")
Do While mas_datos = vbYes
For Each Hoja In Worksheets
Nuevo_Nombre = InputBox("Ingresar el nuevo nombre de la hoja : " & Hoja.Name, "MODIFICAR NOMBRES DE HOJAS ")
If Nuevo_Nombre <> "" Then
Hoja.Name = Nuevo_Nombre
End If
mas_datos = vbNo
Next
Loop
mas_datos = MsgBox("Cierres del período anterior realizados en el mes actual", vbInformation)
Texto = InputBox("Favor de ingresar las primeras tres siglas del mes en curso")
Valor = Val(InputBox("Favor de ingresar número del mes en curso"))
Sheets(Hoja6.Name).Range("x1").Value = Texto
Sheets(Hoja6.Name).Range("y1").Value = Valor
Sheets(Hoja9.Name).Range("V1").Value = Texto
Sheets(Hoja9.Name).Range("U1").Value = Valor
End Sub
Te dejo las instrucciones que necesitas para avanzar con Enter sin cambiar la fecha, dejando en el mismo InputBox el valor por defecto. Las líneas en negrita son las que ya tené´s:
mas_datos = MsgBox("Cierres del período anterior realizados en el mes actual", vbInformation)

Dim mes1, mes2
mes1 = Sheets(6).Range("x1")
mes2 = Sheets(6).Range("y1")
Do
Texto = InputBox("Favor de ingresar las primeras tres siglas del mes en curso", , mes1)
Loop While Texto = ""
Do
Valor = Val(InputBox("Favor de ingresar número del mes en curso", , mes2))
Loop While Valor < 1 Or Valor > 12
Sheets(Hoja2.Name).Range("x1").Value = Texto
Como verás agregué la opción de control para que sea nro de mes válido y no te permita cancelar la ventana sin ingresar datos (es 1 sugerencia- Si no te interesa quitás las líneas del DO y Loop)
Elsa, muchas gracias por tu sugerencia realemne fue muy buena aunque tenia la misma falencia que la mía, por lo cual te cuento que lo pude resolver y agregue un select case quedo así:
Sub AUTO_OPEN()
Dim Nuevo_Nombre As String, Texto As String
Dim Hoja As Worksheet
Dim mas_datos As Integer, Valor As Integer
mas_datos = MsgBox("¿Desea modificar el nombre de la hojas? ", vbYesNo + vbQuestion, "MODIFICAR NOMBRES")
Do While mas_datos = vbYes
For Each Hoja In Worksheets
Nuevo_Nombre = InputBox("Ingresar el nuevo nombre de la hoja : " & Hoja.Name, "MODIFICAR NOMBRES DE HOJAS ")
If Nuevo_Nombre <> "" Then
Hoja.Name = Nuevo_Nombre
End If
mas_datos = vbNo
Next
Loop
mas_datos = MsgBox("Cierres del período anterior realizados en el mes actual", vbInformation)
Texto = InputBox("Ingresar el mes a evaluar")
If Texto <> "" Then
Sheets(Hoja6.Name).Range("x1").Value = Texto
Sheets(Hoja6.Name).Range("y1").Value = Valor
Sheets(Hoja9.Name).Range("V1").Value = Texto
Sheets(Hoja9.Name).Range("U1").Value = Valor
Select Case Texto
Case "enero"
Case "ENERO"
Sheets(Hoja6.Name).Range("x1").Value = "Ene"
Sheets(Hoja6.Name).Range("y1").Value = 1
Sheets(Hoja9.Name).Range("V1").Value = "Ene"
Sheets(Hoja9.Name).Range("U1").Value = 1
Case "febrero"
Case "FEBRERO"
Sheets(Hoja6.Name).Range("x1").Value = "Feb"
Sheets(Hoja6.Name).Range("y1").Value = 2
Sheets(Hoja9.Name).Range("V1").Value = "Feb"
Sheets(Hoja9.Name).Range("U1").Value = 2
Case "marzo"
Case "MARZO"
Sheets(Hoja6.Name).Range("x1").Value = "Mar"
Sheets(Hoja6.Name).Range("y1").Value = 3
Sheets(Hoja9.Name).Range("V1").Value = "Mar"
Sheets(Hoja9.Name).Range("U1").Value = 3
Case "abril"
Case "ABRIL"
Sheets(Hoja6.Name).Range("x1").Value = "Abr"
Sheets(Hoja6.Name).Range("y1").Value = 4
Sheets(Hoja9.Name).Range("V1").Value = "Abr"
Sheets(Hoja9.Name).Range("U1").Value = 4
Case "mayo"
Case "MAYO"
Sheets(Hoja6.Name).Range("x1").Value = "May"
Sheets(Hoja6.Name).Range("y1").Value = 5
Sheets(Hoja9.Name).Range("V1").Value = "May"
Sheets(Hoja9.Name).Range("U1").Value = 5
Case "junio"
Case "JUNIO"
Sheets(Hoja6.Name).Range("x1").Value = "Jun"
Sheets(Hoja6.Name).Range("y1").Value = 6
Sheets(Hoja9.Name).Range("V1").Value = "Jun"
Sheets(Hoja9.Name).Range("U1").Value = 6
Case "julio"
Case "JULIO"
Sheets(Hoja6.Name).Range("x1").Value = "Jul"
Sheets(Hoja6.Name).Range("y1").Value = 7
Sheets(Hoja9.Name).Range("V1").Value = "Jul"
Sheets(Hoja9.Name).Range("U1").Value = 7
Case "agosto"
Case "AGOSTO"
Sheets(Hoja6.Name).Range("x1").Value = "Ago"
Sheets(Hoja6.Name).Range("y1").Value = 8
Sheets(Hoja9.Name).Range("V1").Value = "Ago"
Sheets(Hoja9.Name).Range("U1").Value = 8
Case "septiembre"
Case "SEPTIEMBRE"
Sheets(Hoja6.Name).Range("x1").Value = "Sep"
Sheets(Hoja6.Name).Range("y1").Value = 9
Sheets(Hoja9.Name).Range("V1").Value = "Sep"
Sheets(Hoja9.Name).Range("U1").Value = 9
Case "octubre"
Case "OCTUBRE"
Sheets(Hoja6.Name).Range("x1").Value = "Oct"
Sheets(Hoja6.Name).Range("y1").Value = 10
Sheets(Hoja9.Name).Range("V1").Value = "Oct"
Sheets(Hoja9.Name).Range("U1").Value = 10
Case "noviembre"
Case "NOVIEMBRE"
Sheets(Hoja6.Name).Range("x1").Value = "Nov"
Sheets(Hoja6.Name).Range("y1").Value = 11
Sheets(Hoja9.Name).Range("V1").Value = "Nov"
Sheets(Hoja9.Name).Range("U1").Value = 11
Case "diciembre"
Case "DICIEMBRE"
Sheets(Hoja6.Name).Range("x1").Value = "Dic"
Sheets(Hoja6.Name).Range("y1").Value = 12
Sheets(Hoja9.Name).Range("V1").Value = "Dic"
Sheets(Hoja9.Name).Range("U1").Value = 12
End Select
End If
End Sub
Me gustaría agregarle una opción que si no se ingresa el nombre del mes en minúscula o mayúscula me tire un mensaje de error y permita nuevamente poder ingresarlo, ¿lo relaice de esta manera pero no funciona quizás es porque lo puse al final?
Do
Texto = InputBox("Favor de ingresar las primeras tres siglas del mes en curso", vbcritical)
Loop While Texto < >"enero" Or Texto<> "ENERO"
Mejor te envío mi libro porque funciona perfecto con la rutina anterior. Quizás no te quedó bien ajustada la macro
Podes solicitarlo al correo que encontrarás en mi sitio o dejarme tu mail aquí (no accedemos a los mails de Uds)

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas