+ Reply to Thread
Results 1 to 4 of 4

absolute cell referencing in VBA code

  1. #1
    Registered User
    Join Date
    09-16-2006
    Posts
    28

    Question absolute cell referencing in VBA code

    Using VBA, I want to achieve the following:
    Select sheet1, then select cell A1 (absolute), then input the text "Hello" in A1.

    If you cannot stop laughing, please try to remember the first time you use VBA in Excel.

    Thanks!

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    All referencing in VB is absolute.
    If you want to put "Hello" in Sheet1!A1
    Please Login or Register  to view this content.
    will do it.

    Selecting is not needed and makes things more difficult. The code
    Please Login or Register  to view this content.
    will do what you want, but it will cause an error if Sheet 2 is active

    This avoids that problem, but the first is easier.
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    phuang1226

    Please read forum rules, new rules apply since early this year.- see blue link below.

    The 1st part of your thread title is invalid.

    No question is to trivial.
    Whilst the answer may be simple &/or be of general knowledge to people who play around with VBA code, it is knowledge you do not have and require.

    It can even be a case that you know a way to do something but you may not know the best way to do it. This will be one reason mikerickson has given a detailed reply & not just given one way of acheiving what you are after.

    I have been playing around with VBA code for years & I still come across postings from others that have more efficient code to do something than the code I had been using.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Actually, all referencing in VBA is not absolute. The code below creates a relative reference based on the cell you're in (and using "ActiveCell..." is quite common in VBA).
    Please Login or Register  to view this content.
    If your active cell is A1, yes, it will select cells A1 through B2. But, if your active cell is E5, this code won't select A1:B2, it will select E5:F6 (the equivalent of 2 rows x 2 columns).

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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