Permission denied when trying to get cell values from another sheet

adm1neca

New Member
Joined
Apr 11, 2013
Messages
11
Dear All,

I turn to you, because i ran into some troubles. I want to get the value from certain cell and put it into listbox.

Here is the code i am using
I get permission denied when the for cycle starts. If i have the values of the cells in the same sheet everything works great.

Code:
Private Sub CommandButton1_Click()
crit = Val(ComboBox2.Value)

If ActiveWorkbook.Worksheets("array_db").Cells(Rows.Count, 1).End(xlUp).Row = 1 Then
lr = 2
Else
lr = ActiveWorkbook.Worksheets("array_db").Cells(Rows.Count, 1).End(xlUp).Row
End If
'clear thebox

For x = 2 To lr


If ActiveWorkbook.Sheets("array_db").Cells(x, 1) = crit Then
'write it to the listbox
Me.ListBox1.AddItem ActiveWorkbook.Sheets(8).Cells(x, 1)


Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = ActiveWorkbook.Worksheets("array_db").Cells(x, 2)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = ActiveWorkbook.Worksheets("array_db").Cells(x, 3)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = ActiveWorkbook.Worksheets("array_db").Cells(x, 4)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = ActiveWorkbook.Worksheets("array_db").Cells(x, 5)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = ActiveWorkbook.Worksheets("array_db").Cells(x, 6)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = ActiveWorkbook.Worksheets("array_db").Cells(x, 7)
End If
 
Next x


End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Do you have the RowSource property of the listbox set?
 
Upvote 0
No, but i am adding items with the AddItem. If the cells are in the same sheet it works perfectly fine, however if i want to take them from another i get this problem.
 
Upvote 0
Where exactly do you get the error?

Also, which worksheet is causing the problem?

Is it the worksheet that Sheets(8) refers to if the worksheet with the tab name 'array_db'?
 
Upvote 0
The error is here right after the IF:
Code:
Me.ListBox1.AddItem ActiveWorkbook.Sheets(8).Cells(x, 1)
Yes Sheets(8) is the same as array_db; just wanted to check if that was an issue
 
Upvote 0
What happens if you use Sheets("array_db") instead of Sheets(8)?
 
Upvote 0
What happens if you add this to the code?
Code:
Me.ListBox1.RowSource = ""
 
Upvote 0
Where is this listbox located?

I've been assuming it was on a userform.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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