Hola de nuevo, tengo un formulario con un MonthCalendar para seleccionar un día a partir del cual crear una hoja excel desde otra, es decir seleccionar desde esa fecha todos los registros de la hoja y guardarlos en la nueva. El problema es que me da un error y no sé como solucionarlo. ¿Aalguien me puede echar un cable? Gracias.
**El error que da es: System.Runtime.InteropServices.COMException: 'El índice no es válido. (Excepción de HRESULT: 0x8002000B (DISP_E_BADINDEX))'Código:Private Sub Guarda_btn_Click(sender As Object, e As EventArgs) Handles Guarda_btn.Click valor = fecha_tb.Text exApp = New Excel.Application exApp.Workbooks.Open(archivo) exApp.Range("A1").Select() exApp.ActiveSheet.Select If exApp.Selection.Find(valor) Is Nothing Then MsgBox("ERROR. NO HAY SELECCIONADO NADA.", vbCritical) Else exApp.Selection.Find(valor).Select() NumCol = exApp.ActiveCell.Column NumRow = exApp.ActiveCell.Row End If 'ABRIMOS EL LIBRO exApp.Workbooks.Open(archivo) With exApp Dim hojaOrigen As Worksheet Dim hojaDestino As Worksheet hojaOrigen = .Sheets(Origen) hojaDestino = .Sheets(Destino) 'AQUÍ HAY UN ERROR ** If hojaOrigen Is Nothing Then MsgBox("ERROR. LA HOJA ORIGEN INDICADA NO EXISTE", vbCritical) End If If Not hojaDestino Is Nothing Then MsgBox("ERROR. LA HOJA DESTINO YA EXISTE EN EL LIBRO. " & "INDICA OTRO NOMBRE PARA LA HOJA DESTINO", vbCritical) End If If hojaDestino Is Nothing And Not hojaOrigen Is Nothing Then hojaOrigen = Nothing hojaDestino = Nothing Else hojaOrigen = Nothing hojaDestino = Nothing Exit Sub End If .Sheets.Add() ' AGREGAMOS NUEVA HOJA AL LIBRO .ActiveSheet.Select ' LA SELECCIONAMOS .ActiveSheet.Name = Destino ' LE CAMBIAMOS EL NOMBRE .Sheets(Origen).Select ' NOS POSICIONAMOS EN LA HOJA DE ORIGEN .Range((NumCol, NumRow), exHoja.Cells(exHoja.UsedRange.Rows.Count, exHoja.UsedRange.Columns.Count)).Select() ' SELECCIONAMOS LAS CELDAS .Selection.Copy ' COPIAMOS EL CONTENIDO .Sheets(Destino).Select ' NOS POSICIONAMOS EN LA NUEVA HOJA .Cells.Select() .ActiveSheet.Paste ' PEGAMOS LOS DATOS .Application.CutCopyMode = False .ActiveWorkbook.Save() ' GRABAMOS LOS CAMBIOS EN EL LIBRO End With MsgBox("OK", vbInformation) End Sub