Solved

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

Posted on 2014-04-15
5
201 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
create excel pivot chart 12 41
Route Recommendation 18 31
Msbbox Notice (4 days) 27 58
Select Next Route by Time 4 19
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

770 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