+ Reply to Thread
Results 1 to 9 of 9

Using the result of ADDRESS() function as a range for VBA function

Hybrid View

  1. #1
    Registered User
    Join Date
    01-08-2016
    Location
    Poland
    MS-Off Ver
    2010, Office 365
    Posts
    14

    Using the result of ADDRESS() function as a range for VBA function

    Hi everybody,

    I'm using the excel ADDRESS() function in a formula like "=ADDRESS(MATCH(B43;$A$1:$A$411;0);1)" and as a result I get the matching cell address, say it's "$A$270".

    Now what I want to do is to use this result as an address for a VBA function, that looks like this:

    Function copycomment()
    
    Range(ActiveCell.Offset(0, -1).Value).Copy
    ActiveCell.PasteSpecial xlPasteComments
    
    End Function
    With the function above I would like to get the value of a cell that is left to the active cell, use it as a range for to copy desired cell and paste only a comment of it to the active cell.

    Using cell range as an argument for a function would make a more universal solution, and I also tried it, but failed. I wanted to use this function like: "=copycomment(C43)", where "C43" is an address of cell with the ADDRESS() function result.

    My problem is generally how to pass the cell value (the result of the ADDRESS() function) as a range for my VBA function.

    Any suggestion will be appreciated!
    Attached Files Attached Files
    Last edited by Szczesiu; 01-11-2016 at 05:52 AM. Reason: Adding an example workbook

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Using the result of ADDRESS() function as a range for VBA function

    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 use the paperclip icon to open the upload window.

    View Pic

  3. #3
    Registered User
    Join Date
    01-08-2016
    Location
    Poland
    MS-Off Ver
    2010, Office 365
    Posts
    14

    Re: Using the result of ADDRESS() function as a range for VBA function

    Thanks! Please check now, an example workbook added.

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Using the result of ADDRESS() function as a range for VBA function

    Function() don't have the capacity to add the comment of the current cell.

    Sub() only can able to do the changes.

    Function() can able to retrieve the source cell comment and show it in current cell.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  5. #5
    Registered User
    Join Date
    01-08-2016
    Location
    Poland
    MS-Off Ver
    2010, Office 365
    Posts
    14

    Re: Using the result of ADDRESS() function as a range for VBA function

    Do you mean that it is impossible to add a previously copied comment to an active cell using Excel function in VBA? That would be a bad news.
    Last edited by Szczesiu; 01-11-2016 at 06:15 AM. Reason: improving sentence precision

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Using the result of ADDRESS() function as a range for VBA function

    Quote Originally Posted by Szczesiu View Post
    Do you mean that it is impossible to add a previously copied comment to an active cell using Excel function in VBA? That would be a bad news.
    Yes, function can't do the copy paste process. Instead function can able to display that comment as text string.

  7. #7
    Registered User
    Join Date
    01-08-2016
    Location
    Poland
    MS-Off Ver
    2010, Office 365
    Posts
    14

    Re: Using the result of ADDRESS() function as a range for VBA function

    Unfortunately the internal Excel Add-in that I'm using here can only use a comment as a data input. It seems I will have to make a Sub() procedure then.

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Using the result of ADDRESS() function as a range for VBA function

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    Sub GetComment()
    Dim r As Range
    
    Application.ScreenUpdating = False
    
    For Each r In Range("C2:C" & Range("C" & Rows.Count).End(xlUp).Row).Cells
        If Not Range(r.Value).Comment Is Nothing Then
            With r.Offset(, 1)
                .ClearComments
                .AddComment (Range(r.Value).Comment.Text)
                .Comment.Visible = False
            End With
        End If
    Next r
    
    Application.ScreenUpdating = True
    
    End Sub
    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button

  9. #9
    Registered User
    Join Date
    01-08-2016
    Location
    Poland
    MS-Off Ver
    2010, Office 365
    Posts
    14

    Re: Using the result of ADDRESS() function as a range for VBA function

    Thanks! It works great!

    Right before I have seen your answer I did something like this:
    Sub copy_commment()
    
    Rws = Selection.Rows.Count
    N = 0
    
    Do While N < Rws
     Range(ActiveCell.Offset(0, -1).Value).Copy
     ActiveCell.PasteSpecial xlPasteComments
     ActiveCell.Offset(1, 0).Select
     N = N + 1
    Loop
    
    End Sub
    But your solution seems better as it works faster (it is not switching the active cell). I'm only an ocassional VBA user, so every time I want to do something using VBA I have to learn most things anew
    Thanks again!

+ 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. [SOLVED] Replacing cell address in a formula with the result of ADDRESS function
    By CMG2 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-25-2014, 02:59 AM
  2. [SOLVED] Using function result as cell address
    By El_engineer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-19-2013, 08:19 AM
  3. Move to the result of the address function
    By Wigglebritches in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-20-2013, 12:37 AM
  4. [SOLVED] Using the result of a CELL "address" function in another function
    By jphalverson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-21-2013, 11:36 AM
  5. How do you use ADDRESS function result in a macro as a paste destination
    By phanjoe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2012, 01:10 PM
  6. Convert ADDRESS() function result to literal text
    By ajetrumpet in forum Excel General
    Replies: 6
    Last Post: 03-18-2011, 04:20 PM
  7. Using address function result in an array
    By RLR in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-08-2006, 10:25 PM

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