Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Error 1004: Definido por la aplicación o el objeto

publicado

Muy buenas,

Tengo un código que antes me funcionaba bien y ahora, a raiz de incorporarlo a otra parte de código más amplia en la que realizo otra función, me falla y no encuentro solución:

'Compruebo si hay celdas de cliente sin rellenar
Dim UltimaFila As Double
Dim i As Integer
Dim x As Long
Dim ColumnaObjetivo As Integer
Dim Rango As Object
Dim FindeFila As Long




    'Con esto cambio el color de las celdas sin cliente

    Sheets("DATOS").Range("D2:D2000").Interior.ColorIndex = 0
    ColumnaObjetivo = 4
    UltimaFila = Cells(Rows.Count, ColumnaObjetivo).End(xlUp).Row

    For i = 1 To UltimaFila
        If Cells(i, ColumnaObjetivo) = "" Then
           Cells(i, ColumnaObjetivo).Interior.ColorIndex = 3

        End If

    Next i


    'Definimos el final para que mire hacia arriba (desde el final) cuantas celdas hay

    FindeFila = Cells(2000, 1).End(xlUp).Row

    Set Rango = Range(Cells(2, "D"), Cells(FindeFila, "D"))

    x = Application.WorksheetFunction.CountBlank(Rango)

    If x <> 0 Then

    MsgBox "Hay " & x & " celdas de cliente sin rellenar."

    Else

Más código para otras cosas

End If

El caso es que el problema me lo marca en la línea:

Sheets("DATOS").Range("D2:D2000").Interior.ColorIndex = 0

Y no se a qué es debido. Si saco ese pedazo de código a otro libro si que funciona...

¿Alguna ayuda?

Gracias.

Featured Replies

publicado

La línea de código aparentemente está bien. ¿Qué tipo de error te marca VBA?

publicado
  • Autor

Pues el error que pongo en el título. ¿Podría deberse a que tengo la hoja protegida? Aunque en ese rango en concreto no hay nada protegido...

Mañana pongo el código completo desde el trabajo.

Gracias.

publicado

Hola:

No hay que confundir desprotegido con desbloqueado.

Desprotege la hoja antes de realizar cualquier operación en ella, con independencia de si las celdas están bloqueadas o no.

Busca en la ayuda acerca de Protect/Unprotect.

Saludos

publicado
  • Autor

Pues asunto solucionado.


'Compruebo si hay celdas de cliente sin rellenar
Dim UltimaFila As Double
Dim i As Integer
Dim x As Long
Dim ColumnaObjetivo As Integer
Dim Rango As Object
Dim FindeFila As Long




    'Con esto cambio el color de las celdas sin cliente


    [B][COLOR=#ff0000]ActiveSheet.Unprotect "pass"[/COLOR][/B] 'Desprotejo la hoja para poder hacer cambios y comprobaciones


    Sheets("DATOS").Range("D2:D2000").Interior.ColorIndex = 0
    ColumnaObjetivo = 4
    UltimaFila = Cells(Rows.Count, ColumnaObjetivo).End(xlUp).Row

    For i = 1 To UltimaFila
        If Cells(i, ColumnaObjetivo) = "" Then
           Cells(i, ColumnaObjetivo).Interior.ColorIndex = 3

        End If

    Next i


    'Definimos el final para que mire hacia arriba (desde el final) cuantas celdas hay

    FindeFila = Cells(2000, 1).End(xlUp).Row

    Set Rango = Range(Cells(2, "D"), Cells(FindeFila, "D"))

    x = Application.WorksheetFunction.CountBlank(Rango)

    If x <> 0 Then

    MsgBox "Hay " & x & " celdas de cliente sin rellenar."

    Else

    [B][COLOR=#ff0000]ActiveSheet.Protect "pass"[/COLOR][/B] 'Protejo la hoja de nuevo

Con las lineas en rojo consigo mi propósito.

Puede darse por cerrado el tema. Muchas gracias.

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.