+ Reply to Thread
Results 1 to 5 of 5

Thread: VBA printing column value based on other column value

  1. #1
    Registered User
    Join Date
    10-30-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    17

    VBA printing column value based on other column value

    URGENTLY REQUIRED

    I want a VBA excel program in which the program checks a column which has entries in the form of Y and N. What i want is if the column entry is y then display the entry of the other column which has names in it.

    So display all the names who have Y in other column and display all the names in case of N. For convenience names are in column A and Column D has 'Y' or 'N'.

    I am using userform so it will be very helpful if i am able to display the result in textbox, listbox or something.

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: VBA printing column value based on other column value

    Here's an example of how you could do that during your UserForm's initialization routine. This code will examine all the constants in column D for "N" and add the matching names from column A to a form control called lbNames. If your column D values are the results of formulas, then change the xlConstants to xlFormulas:
    Private Sub UserForm_Initialize()
    Dim listItem As Range, ws As Worksheet
    
    Set ws = Sheets("Sheet1")
    
    For Each listItem In ws.Range("D:D").SpecialCells(xlConstants)
        With Me.lbNAMES
            If listItem = "N" Then .AddItem Range("A" & listItem.Row).Value
        End With
    Next listItem
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-30-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: VBA printing column value based on other column value

    Thank you!!!

  4. #4
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: VBA printing column value based on other column value

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  5. #5
    Registered User
    Join Date
    10-30-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: VBA printing column value based on other column value

    Now the the thing is i want to make sure that there are no duplicates in the listbox, because whenever i click the button it again adds the up the same list and redundancy occurs.
    can u please provide me with the solution for that..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0