Buscar hoja y vista preliminar de rango excel
Tengo un problemita que no he podido resolver, y les paso a describir para que me ayuden:
Tengo un userform con dos combobox y un botón, el primer combobox1 me busca el nombre de la hoja, y el segundo combobox busca el rango a visualizar. El problema resulta cuando por ejemplo el combobox1 no encuentra el nombre de la hoja, pues quiero que si no encuentra el dato me envíe un mensaje de "No encontrado" y si existe la hoja, pues que me deje seguir. Aquí las macros que utilizo:
Private Sub ComboBox1_Change()
If ComboBox1 <> "" Then
Worksheets(ComboBox1.Text).Activate
Else
MsgBox "No existe la planilla " & ComboBox1.Text
End If
End Sub
Private Sub CommandButton1_Click()
If ComboBox2.Text = "PLANILLA CIERRE" Then
Unload Me
ActiveSheet.PrintPreview
End If
If ComboBox2.Text = "PLANILLA IMO" Then
Unload Me
Range("A32:D65").Select
Selection.PrintPreview
Hoja1.Activate
End If
If ComboBox2.Text = "PLANILLA CERES" Then
Unload Me
Range("F32:I65").Select
Selection.PrintPreview
Hoja1.Activate
End If
If ComboBox2.Text = "PLANILLA CONV." Then
Unload Me
Range("K32:N65").Select
Selection.PrintPreview
Hoja1.Activate
End If
If ComboBox2.Text = "DINERO" Then
Unload Me
Range("A72:D80").Select
Selection.PrintPreview
Hoja1.Activate
End If
If ComboBox2.Text = "GRANO" Then
Unload Me
Range("A82:E88").Select
Selection.PrintPreview
Hoja1.Activate
End If
If ComboBox2.Text = "GASTOS" Then
Unload Me
Range("A90:C95").Select
Selection.PrintPreview
Hoja1.Activate
End If
If ComboBox2.Text = "ADELANTOS" Then
Unload Me
Range("K18:M21").Select
Selection.PrintPreview
Hoja1.Activate
End If
Hoja1.Activate
End SubSe que la macro es grande, pero si pueden hacerlo mas corto seria mejor.
1 Respuesta
Respuesta de Dante Amor
1