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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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