Macro to switch to another sheet, grab ref to any cell, paste ref in current sheet??

I am looking for a way (either macro or VBA) to perform one simple task:
while in *any cell* of your choice in the current worksheet, switch to
another specific sheet, choose *any* cell, grab a reference to that
cell (not its value), switch back to the first worksheet and slap in
the reference of the cell in the other sheet.

This would be the automated equivalent of doing the following
manually:

1) Select *any cell* (say *F11*) in the current sheet (Call it
"*Destination*").
2) Press "=" (no "ENTER")
3) Click the tab for the other sheet (call it "*Source*")
4) Select *any cell * (say *D50*) within *Source*
5) Press the ENTER key.
6) *F11* now contains the reference formula: *"=Source!D50"*

Ideas?  

I tried to record a macro to do this, but as soon as I type "=" and
select the tab for the second sheet, I can end the macro without
selecting a specific cell in the "source" sheet and pressing ENTER --
which of course grabs the reference of that one cell, but doesn't allow
me to choose a different cell each time.

Help!!


-- 
drhansenjr
------------------------------------------------------------------------
drhansenjr's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=16686
View this thread: http://www.excelforum.com/showthread.php?threadid=318959

0
11/20/2004 2:42:58 AM
excel.misc 78881 articles. 5 followers. Follow

2 Replies
500 Views

Similar Articles

[PageSpeed] 8

How about pointing and clicking on that other cell:

Option Explicit

Sub testme03()

    Dim myCell As Range
    Dim myOtherCell As Range
    
    Set myCell = ActiveCell
    
    Set myOtherCell = Nothing
    On Error Resume Next
    Set myOtherCell = Application.InputBox(prompt:="Select a cell--any cell", _
                         Type:=8).Cells(1)
    On Error GoTo 0
    
    If myOtherCell Is Nothing Then
        'user cancelled
        'do nothing
    Else
        If myCell.Parent.Parent.Name = myOtherCell.Parent.Parent.Name _
         And myCell.Parent.Name = myOtherCell.Parent.Name Then
            myCell.Formula = "=" & myOtherCell.Address _
                               (rowabsolute:=False, columnabsolute:=False)
        Else
            myCell.Formula = "=" & myOtherCell.Address _
                               (rowabsolute:=False, columnabsolute:=False, _
                                external:=True)
        End If

    End If
    
End Sub

If you want to go to a completely different workbook, select it via Window on
the worksheet menubar.

drhansenjr wrote:
> 
> I am looking for a way (either macro or VBA) to perform one simple task:
> while in *any cell* of your choice in the current worksheet, switch to
> another specific sheet, choose *any* cell, grab a reference to that
> cell (not its value), switch back to the first worksheet and slap in
> the reference of the cell in the other sheet.
> 
> This would be the automated equivalent of doing the following
> manually:
> 
> 1) Select *any cell* (say *F11*) in the current sheet (Call it
> "*Destination*").
> 2) Press "=" (no "ENTER")
> 3) Click the tab for the other sheet (call it "*Source*")
> 4) Select *any cell * (say *D50*) within *Source*
> 5) Press the ENTER key.
> 6) *F11* now contains the reference formula: *"=Source!D50"*
> 
> Ideas?
> 
> I tried to record a macro to do this, but as soon as I type "=" and
> select the tab for the second sheet, I can end the macro without
> selecting a specific cell in the "source" sheet and pressing ENTER --
> which of course grabs the reference of that one cell, but doesn't allow
> me to choose a different cell each time.
> 
> Help!!
> 
> --
> drhansenjr
> ------------------------------------------------------------------------
> drhansenjr's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=16686
> View this thread: http://www.excelforum.com/showthread.php?threadid=318959

-- 

Dave Peterson
0
ec357201 (5290)
11/20/2004 3:10:06 AM
This is great --

I just had to tweak it a bit as follows:

Sub testme03()

Dim myCell As Range
Dim myOtherCell As Range

Set myCell = ActiveCell

Set myOtherCell = Nothing
On Error Resume Next
SHEETS(\"SOURCE\").SELEC
Set myOtherCell = Application.InputBox(prompt:="Select a cell--an
cell", _
Type:=8).Cells(1)
SHEETS(\"DESTINATION\").SELEC

On Error GoTo 0

etc...

Now I just need to figure out how to restrict the selectable range i
the source sheet (or cause the macro to say "oops" if the selected cel
is out of range.

I started by defining range names for the cells at the top and botto
of the list of selectable cells -- 

So I'm trying to do something like (crappy pseudocode):

IF 
[destination-row.column] < [selectable_range_start.column] 
OR
[destination-row.column] > [selectable_range_start.column]
OR
[destination-row.row] < [selectable_range_start.row]
OR 
[destination-row.row] > [selectable_range_end.row]
THEN
msgBox ("WUPS!!")
END IF

Sorry -- I haven't touched VB/VBA in any serious way in several year
-- I am VERY rusty

--
drhansenj
-----------------------------------------------------------------------
drhansenjr's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1668
View this thread: http://www.excelforum.com/showthread.php?threadid=31895

0
11/20/2004 5:42:27 AM
Reply:

Similar Artilces:

Macro warning with no macros
I have a workbook that when I try to open it I get the warning tellin me it contains macros and asking whether I want to Enable or Disabl them. I put no macros, no VB scripts, nothing at all in the workboo other than standard Excel formulas and some charts. I developed it i Excel 2002, SP-2, but have moved it back and forth between tw computers, the other which has Excel 97. Regardless of whether Enable or Disable or change the security settings so as not to get th warning, once the workbook is open even if I go t Tools-Macro-Macros... it lists no macros. How can I find out what's cau...

Another address list ?
Hi - I am running Exchange 2003 on Win2003 SBS edition. Could someone tell me whether it is possible to have another address list which exists separate to the GAL ? So for example if you compose a new message and click on the To button, I would like the users to see the GAL and also another entry underneath saying "External Emails" which will have the external user email addresses in it" How do you go about doing this ? Thanks in advance You would create this in the Address Lists container in Exchange System Manager. "Edward" <dont-mail@me.com> wrote...

saving the history of recently used excel documentsto another comp
Reimaging a computer and wanting to know if I can export the excel history to the new image. Most files are on the network and not sure where they are, don't want to remap them all If you're referring to the files listed at the bottom of the File menu you'd have to run the Regedit program and go to this key: HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Recent Files replacing the "11.0" with your Excel version if different. Then you would have to right click on the Recent Files folder and Export it. After the reimage you would double-click the resultin...

Yet another timers-and-threads question
I've got a requirement to be able to set a timer and be told when it expires, eg by a callback. SetTimer with WM_TIMER is not generally useful, as you have to have a window, and some of the threads in which I want to do this don't have windows. SetTimer with callback function is not generally useful, as it's not sufficient that there's a message pump somewhere in the *application*, there has to be a message pump in the *thread* that calls SetTimer (well documented, that, not), and some of the threads in which I want to do this don't have message pumps. CreateWaitableTime...

Macro
Can anybody tell me how to kick off a macro automatically as file is opened? Regards ...

Macro
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: intel Hi, I'm thinking of buying Mac: Office 2008, but before I do I want to check that I will be able to download Scritpsmart collection of templates without any glitches: <http://www.bbc.co.uk/writersroom/scriptsmart/faq.shtml> Does anyone know if I can do this? Regards, SP. In article <ee98ff5.-1@webcrossing.caR9absDaxw>, StregaItalia@officeformac.com wrote: > Version: 2008 > Operating System: Mac OS X 10.4 (Tiger) > Processor: intel > > Hi, > > I'm thinking of buying Mac: Of...

Run macro automatically.
How do I make a macro run automatically when a worksheet it is attached to is loaded? right click on the sheet tab>view code>left window worksheet>right window activate -- Don Guillett SalesAid Software donaldb@281.com "Excel macro" <Excel macro@discussions.microsoft.com> wrote in message news:DD7AF1E3-9263-4523-AC49-A43ABA1AB9D0@microsoft.com... > How do I make a macro run automatically when a worksheet it is attached to is > loaded? I am unable to find "activate " when I right click on worksheet. ( i assume that you are referring to the windo...

Help with macro/and or formula?
Perhaps this is a silly question, but i just can't figure out how t format this worksheet. The problem is that a lot of the cells hav numbers in them with negative signs in the back instead of in the fron (ie. 23-) and i was wondering if anyone knew of a macro/formula i coul use to quickly fix this problem for all the cells. I would b extremely grateful. Thanks -- brefed1 ----------------------------------------------------------------------- brefed15's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3557 View this thread: http://www.excelforum.com/showthre...

Attached Toolbars Macros
Excel 2003 I have a custom tool bar, this tool bar has several items, each item is pointing to a VBA code. This tool bar is attached to the worksheet. I've copied this spreadsheet to several computers. After I copied the spreadsheet I decided to rename the spreadsheet, after I renamed the spreadsheet the Toolbar Item's macros were still pointing to the old name, I reasigned each tool bar item to the current spreadsheet, saved the spreadsheet and everything was working on my computer, but when I re-copied the new spreadsheet to other computers and I clicked on the Toolbar Item...

unhide multiple sheets
How can I unhide several sheets all at once instead of one sheet at time ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com You can do that with a macro, if it is the same sheets then you can record a macro while you unhide them and then next time run that macro.. Or you can use what I use Sub UnhideSheet() Application.ScreenUpdating = False Dim mySht As Worksheet For Each mySht In ActiveWorkbook.Worksheets mySht.Visible = True Next mySht Application.ScreenUpdating = True ...

VBA Command to Look at cell in an If statement
I need to create a macro in VBA that will look at a specific cell (which contains the result of a lookup formula) in an If statement. Basically it would look at a certian cell, and If that cell had the word "YES", then it would execute a seprate macro. If not, just continue on it merry way. I have tried the following and several variations: Sheets("Print Area").Select Range("BO8:BO8").Select If BO8 = YES Then Call PrintBatch What the program has to do is look at the last entry made in a specific column (hence the use of the Lookup formula in the cell) and...

Protected sheets and running macros
i have a sheet with a macro ran by a normal button at the top. Howeve when i protect the worksheet where ever i click on the sheet the macr executes. Can any one offer any advice on how to stop this? Thanks Robert -- Message posted from http://www.ExcelForum.com hi, i am not able to reproduce the problem, hence i may not be able t provide a panacea for that issue. here is what i suggest. i have a sheet that has a macro that is run when a control toolbo button (that is, not a form button) is clicked. this sheet is protected based on the user logged in. what i have don is to protect t...

Macro Freezes Reading Pane
I have a macro that Sends/Receives Tasks from Project Server into Outlook Tasks. Everything is working fine, except one weird thing that happens. I have the Timer set on the macro and it starts as soon as Outlook starts. The macro gets the tasks from ProjectServer every hour. As soon as the macro starts running the Reading pane freezes in the Inbox. If i stop the macro then Reading pane is back to normal. Can anyone please tell me if there is something I can do in VBA to fix this annoying issue. Thanks a lot ...

Macro to remove rows?
Hi, I receive thousands of rows of data from an extract that comes from a database. The data extract automatically generates page headers that need to be removed, and I would love to automate this process. The headers do have a pattern to them, but I'm not clever enough to figure out a good way to use that to write a macro. The first row of the header starts with hyphens ------------------------------- Then there's a variable number of rows of header data to delete followed by another row of hyphens ------------------------------- Then 2 additional rows that must be deleted. The nu...

Switch To... while calling COM Server
Hi, everybody I'm calling some third party COM Server function from my MFC application. This functions brings up some third party dialog. During this dialog display after 5-6 seconds the dialog "Switch To... The action cannot be completed....Server is busy.." appears. After I close this third party dialog, I have to click "Switch To..." and the rest is fine. Is it possible to figure which other processes are trying to reach this COM Server? How to avoid the appearance of this "Switch To..." dialog? Thank you, Alex "Alex" <alsim123@hotmail.c...

Tracking Sheet help.
Sheet 3 of my workbook is a tracking sheet. In cell B8 (sheet 3) I enter the amount of time's that I've made an entry of time on sheet 2. The times I enter on sheet 2 are used to track vehicles that are passing a set location. On sheet 2 I enter the times in column D. The vehicle's I count have numbers to ID them in column F. The numbers look like 401N1501, 401N1514, 401S1516, 401S1600. The part of the number I need to associate with my count is the first four digits, 401N, 401S. Is it possible to do this? Yep, use a sumproduct function to count using the left 4 digits as...

Calling on a macro within a macro!
Hey All!! Quick Question - How do you call up a macro within a current macro? I have one big macro and I need it to jump to several other macros when it runs! Does it matter where the other macros are stored or is it better to have them all in one module? Help appreciated Thnx! Hi Mellowe, '=============>> Public Sub Main() 'Your code Call One 'your code End Sub '<<============= '=============>> Public Sub One() MsgBox "Hi from One" End Sub '<<============= > Does it matter where the other macros are stored or ...

Can an item you have purchased in the past become a BOM?
We are currently purchasing an item from a vendor (PO history, order history etc) that we are planning on manufacturing ourselves in the next month. I've been tasked to see if there will be any issues with using the same part number we currently ORDER from a vendor to change it into a BOM in the future. I've tested this out in our test company and cannot find any reason why we cannot use the same part number - we simply would not be able to ORDER that part any longer from anyone. Has anyone else ever gone through this process before? any issues? OR is it better to give this i...

transfer investment account from one .mny file to another
Hi, I am using Microsoft Money Plus Home & Business version 17.0.150.1415. I use it to keep track of my personal finances in one .mny file, and I use it to keep track of business finances in another .mny file. In the .mny file for my business, I just created an Investment account and added about ten stocks to it. I should have created this in my personal .mny file. Can anyone tell me if there is a way I can move this one investment account (and the stocks included in it) from my business .mny file to my personal ..mny file? Thanks in advance, Paul -- Paul Kraemer In m...

Trend Line constants as Excel Cell Values
I want to put the constants of a 2 degree polynomial trend line into Excel Cells. Are there formula's to do this? Equation is Y = Ax(2) + Bx + C. I want the value of A,B and C in seperate cells. Can anyone suggest how this can be done? Thanks -- Ken Hi Ken, Supposing your x-range is in A2:A10, and y-range in B2:B10, select a 3-column x 1-row area and enter the following formula and confirm with CTRL-SHIFT-ENTER. =LINEST(B2:B10,A2:A10^{0,1,2},0,) Regards, B. R. Ramachandran "Ken" wrote: > I want to put the constants of a 2 degree polynomial trend line into Excel &g...

shortcut keys to macros
Hi, Is it at all possible to assign shortcut keys to macros in Outlook? Thx, Hans ...

NAICS Code
Hello, I have a list of NAICS codes formatted as numbers that I would like to format as hierarchical text. Current List 10 12 101 112 Desired List 10 101 112 12 Does anyone know how to change the cell format so that the "Current List" becomes the "Desired List"? Thank you in advance for your help. It looks like you could preformat that column as text and enter your values as text. Then you could sort the data as text. Some versions of excel will ask if you want to sort values that look like numbers as numbers. You should say no to that prompt. And just changing t...

help Unable to record Macro !!!!!!!
I want to record a macro in excel.But as soon as I click record Macro it says "unable to record" macro. Got no help in excel help.I do this same thing in word and it's working. Please help It's urgent for me !!!1 Have a look here http://groups.google.com/groups?as_epq=unable%20to%20record&as_ugroup=microsoft.public.excel.* -- Don Guillett SalesAid Software donaldb@281.com "ash" <anonymous@discussions.microsoft.com> wrote in message news:3e0b01c42ae5$45333e00$a401280a@phx.gbl... > I want to record a macro in excel.But as soon as I click > record...

Macro that password protects a sheet
I am attempting to create a macro that can open a protected sheet, change something, and then protect it again. I continue to have an issue with the macro not entering the password. Is this possible to do/fix? Thanks, Ryan ..open password="mypassword" -- Don Guillett SalesAid Software donaldb@281.com "Ryan" <Ryan@discussions.microsoft.com> wrote in message news:D4780ED8-CA1D-4284-97BC-3576160D998E@microsoft.com... > I am attempting to create a macro that can open a protected sheet, change > something, and then protect it again. I continue to have an iss...

Column width and pasting sections in excel? Formatting questions
I am trying to make a spreadsheet in which I need to have varied column widths in different sections, one under another. (they don't need to relate directly, and no major equations going on) for example: xxxxxxxxx|xxxxxxxxxx xxxxxxxxx|xxxxxxxxxx xxxxxxxxx|xxxxxxxxxx xxxxxxx|xxxxx|xxxxxx xxxxxxx|xxxxx|xxxxxx How do I go about splitting the sheet or whatever I need to do so I can manipulate columns differently based on the row I'm in? Thanks! Rich Column widths apply to the whole column. You may be able to use merged cells to give the appearance that you want, but I try to stay...