+ Reply to Thread
Results 1 to 12 of 12

How to refer a cell of another sheet mentioned in a cell through VBA

  1. #1
    Registered User
    Join Date
    07-03-2016
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    38

    Question How to refer a cell of another sheet mentioned in a cell through VBA

    Hi,

    I am having a excel file named Book1 with Sheet1 and Sheet2. In Sheet1, Cell Value of A1 is '[Book1.xlsb]Sheet2'!$A$14, which is derived as some formula result. I want cell mentioned in cell A1 to be selected through VBA.

    I have put VB Code as - Range(Range("A1")).Select or Range([Indirect("A1")]).Select

    This code works only when cell referred in A1 is in same sheet, but it doesn't work if cell referred is in different sheet.. Can someone help to solve this please...

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    Hi,

    I think you are looking for code like:
    Worksheets("Sheet2").Range("A1")
    See:
    http://www.quepublishing.com/article...21718&seqNum=5
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    07-03-2016
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    38

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    Hi Marvin,

    Not exactly I am looking for.. I need result as below:

    (1) Name of my excel file is Book1
    (2) My Current Cell Location is any cell in Sheet1. e.g. Cell B5 in Sheet1
    (3) Value of Cell A1 in Sheet 1 is '[Book1.xlsb]Sheet2'!$A$14
    (4) I want to run a Macro from my current cell location (i.e. Cell B5 of Sheet1) and result of running this macro should land me in Cell Number A14 of Sheet 2 (i.e. Cell Value of A1 in Sheet1)

    Hope I am clear in explaining my query now...

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    Hi,

    It is*much easier for us to understand your question if you supply a sample workbook. If you could attach a sample, we could get you a much better answer.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  5. #5
    Registered User
    Join Date
    07-03-2016
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    38

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    Please find attached file for reference.. There are two macros in file. Macro1 will run and generate desired results, while Macro2 throws error. Please help with solution....
    Attached Files Attached Files

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    Hi,

    Do it like this instead:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-03-2016
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    38

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    It works.. Thanks Buddy..

  8. #8
    Registered User
    Join Date
    07-03-2016
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    38

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    One small issue, which was not covered earlier by me..sorry for that. If I modify code line as below, it throws an error.

    Code Line used by me is : Selection.Copy Destination:=Range(Range("Cells(x,1)"))
    Instead of Code Line provided by you : Selection.Copy Destination:=Range(Range("A1"))

    I need to do this as I am running a For Loop for column A, which gives me copy destination cells... I have defined x as 1 to N (where N is last row used)..

    Any solution???
    Last edited by JigneshBavishi; 02-02-2017 at 03:00 AM.

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    Try:

    Selection.Copy Destination:=Range(Range(Cells(x,1)))

    As you*get better at writing VBA, you will stop using the ".Select" and "Selection" statements. Keep learning and practicing.
    Read sites like:
    http://www.spreadsheet1.com/vba-deve...practices.html
    http://dailydoseofexcel.com/archives...-ill-never-do/

  10. #10
    Registered User
    Join Date
    07-03-2016
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    38

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    Thanks a Ton Sir-ji...

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    Hi,

    The equivalent of
    Please Login or Register  to view this content.
    is actually this
    Please Login or Register  to view this content.
    and not
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  12. #12
    Registered User
    Join Date
    07-03-2016
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    38

    Re: How to refer a cell of another sheet mentioned in a cell through VBA

    Ya, I also noticed that small error in last reply and got it rectified in my excel file.. However forgot to mention the same when marked the thread as resolved... Anyway thanks for your feedback...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 09-22-2014, 06:00 PM
  2. refer other sheet cell , similar to active cell.
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2013, 02:54 PM
  3. Replies: 4
    Last Post: 10-11-2012, 12:44 AM
  4. Refer to cell on another sheet
    By chrisexcel in forum Excel General
    Replies: 2
    Last Post: 06-29-2011, 07:44 AM
  5. To refer to a cell whose address is contained in a cell in another sheet.
    By kmlprtsngh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-15-2010, 03:32 AM
  6. To refer to a cell address from a cell's value in other sheet
    By kmlprtsngh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-13-2010, 11:33 AM
  7. [SOLVED] Refer to sheet name specified in other cell
    By Marko Pinteric in forum Excel General
    Replies: 3
    Last Post: 03-04-2005, 06:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1