Solved

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

Posted on 2014-04-15
5
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 50
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 (Microsoft MVP / EE MVE) 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

691 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