A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Returning values listed under multiple conditions



 
 
Thread Tools Display Modes
  #1  
Old July 20th 12, 06:15 PM
Tee51 Tee51 is offline
Junior Member
 
First recorded activity by ExcelBanter: Mar 2012
Posts: 19
Default Returning values listed under multiple conditions

Hello,

I have two problems:

1) Can someone help me modify the code below so that it pulls data from columns other than column A on sheet1?

2) Can someone help me modify the code below so that the heading in column A sheet3 does not clear?

I’m working on a code that will filter through columns H & I in on sheet1 and list the values from column H that are listed multiple times under different conditions. Sheet1 was used to test the code on text in the same sheet. Sheet3 is used to test the code on an active and inactive sheet. Simply, I was trying to get the return values to appear on a different sheet and it works. But another issue occurred, I cannot figure out how to clear the content in column A of sheet3 without clearing the heading.

Code:
Sub CommandButton1_Click()
    
    Dim Data As Variant
    Dim Dict As Object
    Dim Key As String
    Dim MyList() As Variant
    Dim n As Long
    Dim Rng As Range
    Dim Wks As Worksheet
        
        Set Wks = ActiveSheet
        
        Set Rng = Worksheets("Sheet1").Range("A1").CurrentRegion
        Wks.Columns(1).ClearContents
        
        Data = Rng.Resize(ColumnSize:=2).Value
    
        Set Dict = CreateObject("Scripting.Dictionary")
        
            For i = 1 To UBound(Data, 1)
                Key = Trim(Data(i, 1))
                If Key <> "" Then
                    If Not Dict.Exists(Key) Then
                        Dict.Add Key, Data(i, 2)
                    End If
                    If Dict(Key) <> Data(i, 2) Then
                        ReDim Preserve MyList(n)
                        MyList(n) = Key
                        n = n + 1
                    End If
                End If
            Next i
            
        If Dict.Count > 0 Then
            Wks.Range("A2").Resize(UBound(MyList, 1) + 1).Value = Application.Transpose(MyList)
        End If
            
End Sub
Attached Files
File Type: zip List Multiple Events.zip (18.4 KB, 54 views)
Ads
  #2  
Old July 21st 12, 02:44 PM posted to microsoft.public.excel.worksheet.functions
isabelle
external usenet poster
 
Posts: 449
Default Returning values listed under multiple conditions

hi,

With Wks
.Range(.Cells(2, 1), .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row, 1)).ClearContents
End With


or

With Wks
.Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row).ClearContents
End With

--
isabelle



Le 2012-07-20 13:15, Tee51 a écrit :
> Hello,
>
> I have two problems:
>
> 1) Can someone help me modify the code below so that it pulls data from
> columns other than column A on sheet1?
>
> 2) Can someone help me modify the code below so that the heading in
> column A sheet3 does not clear?
>
> I’m working on a code that will filter through columns H& I in on
> sheet1 and list the values from column H that are listed multiple times
> under different conditions. Sheet1 was used to test the code on text in
> the same sheet. Sheet3 is used to test the code on an active and
> inactive sheet. Simply, I was trying to get the return values to appear
> on a different sheet and it works. But another issue occurred, I cannot
> figure out how to clear the content in column A of sheet3 without
> clearing the heading.
>
>
> Code:
> --------------------
>
> Sub CommandButton1_Click()
>
> Dim Data As Variant
> Dim Dict As Object
> Dim Key As String
> Dim MyList() As Variant
> Dim n As Long
> Dim Rng As Range
> Dim Wks As Worksheet
>
> Set Wks = ActiveSheet
>
> Set Rng = Worksheets("Sheet1").Range("A1").CurrentRegion
> Wks.Columns(1).ClearContents
>
> Data = Rng.Resize(ColumnSize:=2).Value
>
> Set Dict = CreateObject("Scripting.Dictionary")
>
> For i = 1 To UBound(Data, 1)
> Key = Trim(Data(i, 1))
> If Key<> "" Then
> If Not Dict.Exists(Key) Then
> Dict.Add Key, Data(i, 2)
> End If
> If Dict(Key)<> Data(i, 2) Then
> ReDim Preserve MyList(n)
> MyList(n) = Key
> n = n + 1
> End If
> End If
> Next i
>
> If Dict.Count> 0 Then
> Wks.Range("A2").Resize(UBound(MyList, 1) + 1).Value = Application.Transpose(MyList)
> End If
>
> End Sub
>
> --------------------
>
>
> +-------------------------------------------------------------------+
> |Filename: List Multiple Events.zip |
> |Download: http://www.excelbanter.com/attachment.php?attachmentid=481|
> +-------------------------------------------------------------------+
>
>
>

  #3  
Old July 26th 12, 03:56 PM
Tee51 Tee51 is offline
Junior Member
 
First recorded activity by ExcelBanter: Mar 2012
Posts: 19
Default

Quote:
Originally Posted by isabelle View Post
hi,

With Wks
.Range(.Cells(2, 1), .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row, 1)).ClearContents
End With


or

With Wks
.Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row).ClearContents
End With

--
isabelle



Le 2012-07-20 13:15, Tee51 a écrit :
> Hello,
>
> I have two problems:
>
> 1) Can someone help me modify the code below so that it pulls data from
> columns other than column A on sheet1?
>
> 2) Can someone help me modify the code below so that the heading in
> column A sheet3 does not clear?
>
> I’m working on a code that will filter through columns H& I in on
> sheet1 and list the values from column H that are listed multiple times
> under different conditions. Sheet1 was used to test the code on text in
> the same sheet. Sheet3 is used to test the code on an active and
> inactive sheet. Simply, I was trying to get the return values to appear
> on a different sheet and it works. But another issue occurred, I cannot
> figure out how to clear the content in column A of sheet3 without
> clearing the heading.
>
>
> Code:
> --------------------
>
> Sub CommandButton1_Click()
>
> Dim Data As Variant
> Dim Dict As Object
> Dim Key As String
> Dim MyList() As Variant
> Dim n As Long
> Dim Rng As Range
> Dim Wks As Worksheet
>
> Set Wks = ActiveSheet
>
> Set Rng = Worksheets("Sheet1").Range("A1").CurrentRegion
> Wks.Columns(1).ClearContents
>
> Data = Rng.Resize(ColumnSize:=2).Value
>
> Set Dict = CreateObject("Scripting.Dictionary")
>
> For i = 1 To UBound(Data, 1)
> Key = Trim(Data(i, 1))
> If Key<> "" Then
> If Not Dict.Exists(Key) Then
> Dict.Add Key, Data(i, 2)
> End If
> If Dict(Key)<> Data(i, 2) Then
> ReDim Preserve MyList(n)
> MyList(n) = Key
> n = n + 1
> End If
> End If
> Next i
>
> If Dict.Count> 0 Then
> Wks.Range("A2").Resize(UBound(MyList, 1) + 1).Value = Application.Transpose(MyList)
> End If
>
> End Sub
>
> --------------------
>
>
> +-------------------------------------------------------------------+
> |Filename: List Multiple Events.zip |
> |Download: http://www.excelbanter.com/attachment.php?attachmentid=481|
> +-------------------------------------------------------------------+
>
>
>
Hi,

Thanks for the response. The first code works perfectly. Do you know how to change the code so that it uses date from column H instead of column A?
  #4  
Old July 27th 12, 01:17 AM posted to microsoft.public.excel.worksheet.functions
isabelle
external usenet poster
 
Posts: 449
Default Returning values listed under multiple conditions

yes, you must replace 1 by 8

With Wks
.Range(.Cells(2, 8), .Cells(.Cells(.Rows.Count, 8).End(xlUp).Row, 8)).ClearContents
End With

--
isabelle


> Hi,
>
> Thanks for the response. The first code works perfectly. Do you know how
> to change the code so that it uses date from column H instead of column
> A?

  #5  
Old August 21st 12, 08:19 PM
Tee51 Tee51 is offline
Junior Member
 
First recorded activity by ExcelBanter: Mar 2012
Posts: 19
Default

Sorry for the delay.

That suggestion did not help maybe I am missing something.

Code:
Sub CommandButton1_Click()
    
    Dim Data As Variant
    Dim Dict As Object
    Dim Key As String
    Dim MyList() As Variant
    Dim n As Long
    Dim Rng As Range
    Dim Wks As Worksheet
        
        Set Wks = ActiveSheet
        
        Set Rng = Worksheets("Sheet1").Range("A1").CurrentRegion
        With Wks
        .Range(.Cells(2, 8), .Cells(.Cells(.Rows.Count, 8).End(xlUp).Row, 8)).ClearContents
        End With


        
        Data = Rng.Resize(ColumnSize:=2).Value
    
        Set Dict = CreateObject("Scripting.Dictionary")
        
            For i = 1 To UBound(Data, 1)
                Key = Trim(Data(i, 1))
                If Key <> "" Then
                    If Not Dict.Exists(Key) Then
                        Dict.Add Key, Data(i, 2)
                    End If
                    If Dict(Key) <> Data(i, 2) Then
                        ReDim Preserve MyList(n)
                        MyList(n) = Key
                        n = n + 1
                    End If
                End If
            Next i
            
        If Dict.Count > 0 Then
            Wks.Range("A2").Resize(UBound(MyList, 1) + 1).Value = Application.Transpose(MyList)
        End If
            
End Sub

Last edited by Tee51 : August 21st 12 at 08:27 PM. Reason: Adding info
  #6  
Old August 22nd 12, 01:51 AM posted to microsoft.public.excel.worksheet.functions
isabelle
external usenet poster
 
Posts: 449
Default Returning values listed under multiple conditions

hi,

With Worksheets("Sheet1")
.Range(.Cells(1, 8), .Cells(.Cells(.Rows.Count, 8).End(xlUp).Row, 8)).ClearContents
End With


--
isabelle



Le 2012-08-21 15:19, Tee51 a écrit :
> Sorry for the delay.
>
> That suggestion did not help maybe I am missing something.
>
>

  #7  
Old August 22nd 12, 01:30 PM
Tee51 Tee51 is offline
Junior Member
 
First recorded activity by ExcelBanter: Mar 2012
Posts: 19
Question

That code cleared out Column H and is still returning Column A values.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning a value if multiple conditions are met Joel Excel Worksheet Functions 2 May 29th 10 03:05 AM
Returning a value if multiple conditions are met Jacob Skaria Excel Worksheet Functions 0 May 27th 10 09:28 PM
Looking up multiple values and returning one corresponding value Nightrain Excel Worksheet Functions 10 September 2nd 08 03:55 PM
returning values from columns to another sheet, based on conditions zangief Excel Programming 1 September 26th 05 08:13 PM
How to calculate values in multiple values with multi conditions Curtis Excel Worksheet Functions 2 July 15th 05 02:36 AM


All times are GMT +1. The time now is 08:14 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2004-2013 ExcelBanter.
The comments are property of their posters.