Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel formula with SUMIF and SUBTOTAL 13 45
Take Space out of Email 11 41
Excel -  lookup two values and return a value 3 28
Zip Codes Excel Spreadsheet 4 22
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

732 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