+ Reply to Thread
Results 1 to 4 of 4

Display Values of Column/Range/Array/Other

Hybrid View

  1. #1
    Registered User
    Join Date
    11-21-2008
    Location
    USA
    Posts
    3

    Display Values of Column/Range/Array/Other

    [I "moved" this thread to the general section.]

    I haven't seen anyone ask or address this question. I want to automagically list the values/contents of a range, column or an array. And I do not want to manually do anything other than repopulate the contents of the range/column/array.

    For example:

    Column A has a row value in each cell from A1:A100. So each row is 1, 2, 3, 4,.... 99, 100.

    I want Column B to list all the values of Column A without any touching of Column B.

    If I add/change/remove any values of Column A, Column B is auto-updated.

    So far, the best solution I have found, is to count the number of values in Column A and then past a range directly into Column B, not B1 but the Column B, "=A$1:A$XXXXXXX". Sadly this works but it also fills out the column to the maximum amount of rows allowed. This is what I am trying to avoid.

    Thanks!
    Last edited by Laelsa; 11-21-2008 at 02:51 PM.

  2. #2
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    I am sure there is a better solution but this macro will update Column B with the Column A values everytime you run it.

    Sub TEST()
    Dim Ln As Integer
    Dim Pop As Integer
    
    Ln = 1
    Pop = 1
    
    'Counts the number of lines of data in Column A
    Do Until Cells(Ln, 1) = ""
        Ln = Ln + 1
    Loop
    
    'Populates Column B with the formula down to the same number of rows as Column A has
    Do Until Pop = Ln
        Cells(Pop, 2) = "=A" & Pop
        Pop = Pop + 1
    Loop
    End Sub

  3. #3
    Registered User
    Join Date
    11-21-2008
    Location
    USA
    Posts
    3
    Thanks for the macro, Chris.

  4. #4
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    No probs, incidently I thought if you want it to update when any value is change/added in Column A then right click on your worksheet, select view code, and use the following. Any change to column A will then trigger this macro. Let me know if you need anymore help.

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    
    Dim Ln As Integer
    Dim Pop As Integer
    
    Ln = 1
    Pop = 1
    
    If Target.Column = 1 Then
    
        Do Until Cells(Ln, 1) = ""
            Ln = Ln + 1
        Loop
        Do Until Pop = Ln
            Cells(Pop, 2) = "=A" & Pop
            Pop = Pop + 1
        Loop
    End If
    
    End Sub

+ 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