+ Reply to Thread
Results 1 to 4 of 4

VBA Code Referencing a cell

  1. #1
    Forum Contributor
    Join Date
    10-19-2016
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    226

    VBA Code Referencing a cell

    Hi,

    I am trying to reference a cell in a Macro which changes to a named person in the Excel file every time I use a lookup table. The Macro references the name of the person but I want it to reference a particular cell in Excel instead of the persons name, this way, when the excel file is changed to a different person's named data, I don't get an error when running the macro. At the moment, i am getting around the problem by typing the name of the person in the VBA code and then running the macro.

    At the moment the VBA code displays this


    Sheets("John Smith").Select


    Can I put something instead of "John Smith" in the VBA code which will mean I don't get an error when running the macro, for example a reference to the cell which contains the name of the person in the excel file?

    Many thanks
    Last edited by cosmica67; 09-22-2019 at 12:14 PM. Reason: Solved

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: VBA Code Referencing a cell

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Contributor
    Join Date
    10-19-2016
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    226

    Re: VBA Code Referencing a cell

    Many Thanks!

    The solution you gave worked a treat!

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: VBA Code Referencing a cell

    You're welcome and thanks for rep+.

+ 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. Can't determine which bit of my code is referencing incorrect cell
    By JCrinage in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-03-2017, 10:28 AM
  2. Help with Referencing a Cell Relative to Active Cell in Custom Function Code
    By mjjb99 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-07-2016, 09:33 PM
  3. Code referencing another Cell
    By vzwtester in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-13-2013, 01:00 PM
  4. Referencing a specific cell after found using VB code
    By phaley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-07-2008, 07:07 PM
  5. code for cell referencing in VBA
    By KK1811 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-30-2007, 03:21 AM
  6. absolute cell referencing in VBA code
    By phuang1226 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2007, 11:57 PM
  7. Cell Referencing Code Error?
    By MPS0525 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-17-2006, 11:45 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