+ Reply to Thread
Results 1 to 5 of 5

Change cells based on their Cell Address

Hybrid View

  1. #1
    Registered User
    Join Date
    11-07-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Office 365
    Posts
    71

    Question Change cells based on their Cell Address

    Hello good Excel people!

    I have a, I expect, simple question regarding using absolute cell addresses to change a given cell.

    I have a piece of code as stated underneath, The output is an absolute cell address: [test.xlsm]Sheet1'!R3C3

    Sub Cell_adresser()
    
    Arow = 3
    Acol = 3
    
    Sheets(1).Cells(4, 2).Value = Worksheets(2).Cells(Arow, Acol).Address(ReferenceStyle:=xlR1C1, External:=True) 'Reads cell adress
    Sheets(1).Cells(4, 3).Value = Worksheets(2).Cells(3, 3).Value
    
    End Sub
    I want to list a long array of cell values and their addresses and then change their value. How do I use this absolute cell address as the reference?

    "For this cell address, do something"


    Hope that makes sense, Thank You


    GregersDK

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Change cells based on their Cell Address

    'Do something' - what exactly are you trying to do? You can reference a cell directly, depending on the method you intend to use...
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    11-07-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Office 365
    Posts
    71

    Re: Change cells based on their Cell Address

    So I have a table with three columns:

    Cell Address | Value option one | Value option two

    This table will be made from the showed Cell_Addresser (when I put it into a loop).

    I want to choose a cell value between the options based on an IF statement. Something like showed below, but using the cell address read from the table instead of the Cells(1,1).Value.

    Sub Address_reader()
    
    Dim Cell_option As Integer
    
    Cell_option = Sheets(1).Cells(1, 1).Value
    
    If Cell_option = 1 Then
        
        Sheets(2).Cells(1, 2).Value = "Option 1"
    
    ElseIf Cell_option = 2 Then
        Sheets(2).Cells(1, 2).Value = "Option 2"
        
    End If
    
    
    End Sub
    The Cell references marked with red, instead of using Cell(y,x) I'd like to refer to the cell address I have printed in Sheets(1).Cells(4, 2), in general terms.

    In all ways I can readily imagine, I keep referring to the cell I'm looking at and not the address I have stated in the cell's value.

    I think in general my question is: How can I read and refer the address written in a cell instead of the Range(A1) or the Cells(1,1)?

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Change cells based on their Cell Address

    Something like this:
    Sub foo()
        Dim c As Range
        Dim iCellOption As Integer
        
        With Sheet1
            iCellOption = .Cells(1, 1).Value
            For Each c In .ListObjects("Table1").ListColumns("Cell Address").DataBodyRange
                Range(c.Text).Value = c.Offset(0, iCellOption)
            Next c
        End With
    End Sub
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-07-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Office 365
    Posts
    71

    Re: Change cells based on their Cell Address

    Thank you! I'll take a look!

    It seems you can just refer to addresses through the Range(c.Text).Value if I'm not mistaken, as a general thing?

    But thank you for setting into context in tables too!

+ 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. Change cell fill color for all cells in a workbook based on a cell value
    By HDeuce in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2017, 06:01 PM
  2. Change the color of Cells based on the value of another Cell
    By dml1783 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-30-2015, 02:40 AM
  3. Change a cells address based on values in another cell.
    By exclusiveicon in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-05-2014, 06:21 PM
  4. [SOLVED] Trying to change font in a frozen cell based on the address of the active cell. Possible?
    By sdavison in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2013, 01:23 AM
  5. Change Email Address based on cell value
    By paxile2k in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-20-2011, 05:17 PM
  6. Change Colour of 3 Cells based on Value of Other Cell
    By hazza147 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2010, 05:57 AM
  7. Change cell values based on Active Cell Address in Excel 2007 with no VBA
    By bdmistri in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-07-2009, 02:01 PM

Tags for this Thread

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