Error 70 en tiempo de ejecución formularios vba

Adablablas

New Member
Joined
Mar 15, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Buenas tardes/dias. estoy haciendo un tipo de base de datos con visual basic. En cierto punto del código me tira el error 70 en tiempo de ejecución "permiso denegado" y no sé bien como solucionarlo. El código
es este
VBA Code:
Private Sub TextBox1_Change()
Dim list() As Variant, x As Long, y As Long, coinci As Boolean, k As Integer
coinci = False
y = 0
k = Me.ComboBox1.ListIndex
Select Case k
    Case Is = 0
    
    For x = 2 To Sheets(2).Range("B" & Rows.Count).End(xlUp).Row
        If InStr(1, UCase(Sheets(2).Range("C" & x).Value), UCase(Me.TextBox1.Value)) > 0 Then
            coinci = True
            ReDim Preserve list(15, y)
            list(1, y) = Sheets(2).Range("b" & x).Text
            list(2, y) = Sheets(2).Range("c" & x).Text
            list(3, y) = Sheets(2).Range("d" & x).Text
            list(4, y) = Sheets(2).Range("e" & x).Text
            list(5, y) = Sheets(2).Range("f" & x).Text
            list(6, y) = Sheets(2).Range("g" & x).Text
            list(7, y) = Sheets(2).Range("h" & x).Text
            list(8, y) = Sheets(2).Range("i" & x).Text
            list(9, y) = Sheets(2).Range("j" & x).Text
            list(10, y) = Sheets(2).Range("k" & x).Text
            list(11, y) = Sheets(2).Range("l" & x).Text
            list(12, y) = Sheets(2).Range("m" & x).Text
            list(13, y) = Sheets(2).Range("n" & x).Text
            list(14, y) = Sheets(2).Range("o" & x).Text
            y = y + 1
        End If
    Next
    If coinci = True Then
        Me.ListBox1.list = Application.Transpose(list)
    Else
        Me.ListBox1.RowSource = ""
    End If
End Select

End Sub
Esto es para realizar un filtro en un listbox con un textbox.
Adjunto una foto del formulario ocupado en este
 

Attachments

  • imagen_2023-03-15_150320590.png
    imagen_2023-03-15_150320590.png
    21.2 KB · Views: 37

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
It looks like the error occurs on this line...

VBA Code:
Me.ListBox1.list = Application.Transpose(list)

That's probably because the RowSource property of ListBox1 has a value assigned to it. You'll need to make sure that the RowSource property has no value prior assigning list() to Me.ListBox1.list. So, for example...

VBA Code:
    If coinci = True Then
        me.ListBox1.RowSource = ""
        Me.ListBox1.list = Application.Transpose(list)
    Else
        Me.ListBox1.RowSource = ""
    End If

Hope this helps!
 
Upvote 0
Solution
You're very welcome, glad I could help. By the way, unless you have an Option Base 1 statement at the top of your module, this array...

VBA Code:
ReDim Preserve list(15, y)

...is being declared as a 0-based array, which means that the indexing starts at 0. It's the same as declaring like this...

VBA Code:
ReDim Preserve list(0 to 15, 0 to y)

So you actually have a 16-Row by (y+1)-Column array. If you want to declare a 1-based array so that the indexing starts at 1...

VBA Code:
ReDim Preserve list(1 to 15, 1 to y)

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top