Solved

Referring to a specific cell on a sheet other than the current

Posted on 2014-04-15
5
200 Views
Last Modified: 2014-04-21
There are some tasks I want to perform on each sheet in a workbook and I'd like to do this without Select and/or Activate statements.  I utilize a cell on each sheet as my "home base" and then offset from there, however, when I try to assign a variable name to a cell on a sheet other than the current one, I get a 1004 error.  My code is as follows:
Set HomeSpot = Sheets("SheetsNum").Range("a1") .Range("B4")

Open in new window

This is the line that errors out, even if I just do a short macro trying to select the cell on another sheet.  How can I rewrite the code to pass muster?  Thanks!
P.S. Same error if I precede the above code with "Acvtiveworkbook." and/or use Worksheets instead of Sheets .
0
Comment
Question by:pmpatane
  • 3
  • 2
5 Comments
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 40002670
Hello,

remove the ".Range("B4") from that line of code. You can only have only one range in the Set statement.

cheers, teylyn
0
 

Author Comment

by:pmpatane
ID: 40004157
Sorry, that was a mis-paste.  It is Set HomeSpot = Sheets("SheetsNum").Range("B4"), and it still gives the 1004 error
0
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst earned 500 total points
ID: 40005078
Try to qualify the workbook. This works in my tests:

Sub test()
Dim wb As Workbook
Dim ws As Worksheet
Dim HomeSpot As Range

Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet3")
Set HomeSpot = ws.Range("A1")

HomeSpot.Value = "Hello World"

End Sub 

Open in new window


cheers, teylyn
0
 

Author Comment

by:pmpatane
ID: 40011938
Sorry for the delay, I have been out of the office.  Teylyn, I will check your suggestion first thing tomorrow...thanks!
0
 

Author Closing Comment

by:pmpatane
ID: 40013632
Thanks!  Sorry for my delay...sometimes I don't get all the overhead, but I'm sure there's a reason
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now