Permission Denied error when I try to run my code

2020Rivalry

New Member
Joined
Apr 12, 2022
Messages
35
Office Version
  1. 365
Platform
  1. Windows
I created a userform recently, inside of it got 14 columns. Now I want to use a textbox to filter the data based on one single column. But the error message: Permission Denied keep popping out. Any helps?

Thank you very much!

VBA Code:
Private Sub txtSearch_Change()

    Dim myList() As Variant
    Dim X As Long
    Dim Y As Long
    Dim FoundSomething As Boolean
    Y = 0
    For X = 6 To Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
        If InStr(1, UCase(Sheets("Sheet1").Range("A" & X).Value), UCase(txtSearch)) > 0 Then
            FoundSomething = True
            ReDim Preserve myList(Y)
            myList(Y) = Sheets("Sheet1").Range("A" & X).Text
            Y = Y + 1
        End If
    Next
    
    If FoundSomething Then
        ListBox.ColumnCount = 14
        ListBox.ColumnHeads = True
        ListBox.ColumnWidths = "55,220,100,100,70,70,70,55,130,80,80,70,150,150"
       [COLOR=rgb(250, 197, 28)][B] [/B][/COLOR][COLOR=rgb(71, 85, 119)][B]Me.ListBox.List = myList()[/B][/COLOR]
    Else
        Call Refresh_data
    End If

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Forgot to allow for your data starting in row 6, if there is only one match, try
VBA Code:
         ElseIf UBound(Rws) = 0 Then
            [CODE=vba]myList = .Parent.Range("A" & Rws(0) + .Row - 1).Resize(, 14).Value
Else

[/CODE]
Hi Fluff, actually I couldn't understand your code (I'm still very new to Excel VBA), can you explain more to me,

Like code below:
VBA Code:
Rws = Filter(.Worksheet.Evaluate(Replace("transpose(if(isnumber(search(""" & Me.TextBox1.Value & """,@)),row(@)-min(row(@))+1,false))", "@", .Columns(1).Address)), False, False)
It is beautiful but how it works?

And also:
VBA Code:
myList = .Parent.Range("A" & Rws(0) + .Row - 1).Resize(, 14).Value
Like why we need to add + .Row - 1

Thank you very much!!!
 
Upvote 0
This part
VBA Code:
Rws = Filter(.Worksheet.Evaluate(Replace("transpose(if(isnumber(search(""" & Me.TextBox1.Value & """,@)),row(@)-min(row(@))+1,false))", "@", .Columns(1).Address)), False, False)
Is effectively an Excel formula that says
Excel Formula:
=TRANSPOSE(IF(ISNUMBER(SEARCH( Me.TextBox1.Value, A2:A100)),ROW(A2:A100)-MIN(ROW(A2:A100))+1))
so it returns the row number for all rows that match the search value.

The + .Row - 1is to convert the row number from the data into the actual row. So if the 1st row of data matched the search Rws(0) would be 1, but the actual row is 6
 
Upvote 0
This part
VBA Code:
Rws = Filter(.Worksheet.Evaluate(Replace("transpose(if(isnumber(search(""" & Me.TextBox1.Value & """,@)),row(@)-min(row(@))+1,false))", "@", .Columns(1).Address)), False, False)
Is effectively an Excel formula that says
Excel Formula:
=TRANSPOSE(IF(ISNUMBER(SEARCH( Me.TextBox1.Value, A2:A100)),ROW(A2:A100)-MIN(ROW(A2:A100))+1))
so it returns the row number for all rows that match the search value.

The + .Row - 1is to convert the row number from the data into the actual row. So if the 1st row of data matched the search Rws(0) would be 1, but the actual row is 6
means current code only can search through 100 rows?
 
Upvote 0
VBA Code:
Rws = Filter(.Worksheet.Evaluate(Replace("transpose(if(isnumber(search(""" & Me.TextBox1.Value & """,@)),row(@)-min(row(@))+1,false))", "@", .Columns(1).Address)), False, False)

For this code can I change to
VBA Code:
Rws = Filter(.Worksheet("Sheet1").Evaluate(Replace("transpose(if(isnumber(search(""" & Me.TextBox1.Value & """,@)),row(@)-min(row(@))+1,false))", "@", .Columns(1).Address)), False, False)
??
 
Upvote 0
Ok...because my excel now keep crashing with this error: Method 'Value' of object 'Range'. But before implementing the code, this problem never happen.. I wonder if it goes into an infinite loop as I didn't mention clear enough to the Excel.
 
Upvote 0
You have already mentioned that in another thread & so you must keep it in that thread.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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