I am trying to create a density map in excel. The map will be in a seperate worksheet then where the data is stored. The problem I am having right now is being able to access the data in a separate worksheet then the one my vba function is running in. I thought I could do it like this:
Dim row As Range
' Loop through rows 4 -> 550
For x = 4 To 550
Set row = Worksheet(1).Range(Cells(x, 1)开发者_如何学编程, Cells(x, 24)) ' get range of cells for further processing
Next Counter
the problem is when I run the code just to test it is getting something excel returns the follow error about "Worksheet(1)":
Compile Error:
Sub or Function not defined
All my data is stored in Worksheet #1 and the density map is being created in Worksheet #6. How can i go about doing this
You should consider using this
Set row = Worksheets(1).Cells(x,1).Resize(1,24)
The Range reference is qualified by Worksheets(1) so it will always point to a range on that worksheet. Your Cells references are unqualified and will point to a range on the ActiveSheet, which you may not want.
My bad I was calling worksheet(index) instead of worksheets(index) <- notice that this is plural, there is an "s" at the end of worksheet.
精彩评论