Question: How do I retrieve values after creating an autofilter.

So the question is sort of simple but my code is below, this is my first time really running in VBA but it isn't so far all to dissimilar to LotusScript which I am a bit more knowledgeable in. What I am trying to do is retrieve values from the filtered information,
or more simply, I am trying to retrieve values from two cells in the spreadsheet that I want move together.
As noted below one of them is a countries field which simply concatenates the country string with the duplicates with the same first column (A#) fields. 
Example 123 .. UK
              123 .. US
              123 .. CA
The output stored in countries would be UK,US,CA and posted to sheet3.
Sub proFirst()
Dim wSheet As Worksheet
Dim columnCount As Integer
Dim rowCount As Long
Dim testVar As Long
Dim coll As New Collection, a
Dim Assignee() As String
Dim tmpList() As String
Dim newVar As Variant
Dim dict As Object
Const rowDataBegin = 2
Dim count As Long
rowCount = Sheets("Sheet1").UsedRange.Rows.count
columnCount = Sheets("Sheet1").UsedRange.Columns.count
'** This Cleans up the filtering to ensure all data is viewable before we begin **
Sheets("Sheet1").Activate
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
  ActiveSheet.ShowAllData
End If
Sheets("Sheet3").Activate
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
  ActiveSheet.ShowAllData
End If
'** This sets a filter to filter by column O which is designated as Submitted Date  **
Sheets("Sheet1").Columns("A:S").AutoFilter Field:=15, Criteria1:="<>"
'** This block copuies and pastes the values we need for the final report however   **
'** this is not a permenent viewable format for the report, a recut may be required **
Application.CutCopyMode = False
rowCount = Sheets("Sheet1").UsedRange.Rows.count
Sheets("Sheet1").Range("A1:D" & rowCount).Copy Sheets("Sheet3").Range("A1:D" & rowCount)
Application.CutCopyMode = False
Sheets("Sheet1").Range("J1:J" & rowCount).Copy Sheets("Sheet3").Range("H1:H" & rowCount)
Application.CutCopyMode = False
Sheets("Sheet1").Range("O1:O" & rowCount).Copy Sheets("Sheet3").Range("I1:I" & rowCount)
Application.CutCopyMode = False
'loops through the first column and acquires all of the data and generates as string array
rowCount = Sheets("Sheet3").UsedRange.Rows.count
columnCount = Sheets("Sheet3").UsedRange.Columns.count
ReDim Assignee(rowCount)
ReDim tmpList(rowCount) 'helper variant to make it smoother for recall of lines
For i = rowDataBegin To rowCount
    Assignee(i - rowDataBegin) = CStr(Sheets("Sheet3").Cells(i, 1).Value)
    tmpList(i - rowDataBegin) = rowCount
Next i
Set dict = CreateObject("Scripting.Dictionary")
For i = LBound(Assignee) To UBound(Assignee)
   If dict.exists(Assignee(i)) Then
        dict.Item(Assignee(i)) = dict.Item(Assignee(i)) + 1
         Else
        dict.Add Assignee(i), 1
    End If
   Next i
Sheets("Sheet3").Range("$A$1:$I$" + CStr(rowCount)).RemoveDuplicates Columns:=1, Header:=xlYes
rowCount = 2
Application.Workbooks(1).Worksheets("Sheet3").Activate
'** Header values Change as needed                                                             
Sheets("Sheet3").Cells(1, 5).Value = "Completed Global Questionnaire? (Yes or No)"
Sheets("Sheet3").Cells(1, 6).Value = "Number of Countries"
Sheets("Sheet3").Cells(1, 7).Value = "Name of Countries Submitted"
For Each v In dict.keys
If dict.Item(v) > 0 And v <> "" Then
Sheets("Sheet3").Cells(rowCount, 6).Value = dict.Item(v)
rowCount = rowCount + 1
End If
Next v
Sheets("Sheet3").Columns("A:I").AutoFilter Field:=6, Criteria1:=">1", _
        Operator:=xlAnd
'** BEGIN TESTING AREA
'** Stage 2 Test Complete - able to retrieve a list of how many rows are in use
'** Stage 3 test - retrieve countries
Sheets("Sheet1").Activate
count = 2
For Each v In dict.keys
countries = ""
rowCount = 0
If dict.Item(v) > 1 Then
    With ActiveSheet
       Set rnData = .UsedRange
        With rnData
            .AutoFilter Field:=1, Criteria1:=v
           .Select
            'xlCellTypeVisible = 12
             For Each rngArea In .SpecialCells(xlCellTypeVisible).Areas
             tmp = .SpecialCells(xlCellTypeVisible).Rows
            Next
            For Z = 2 To rowCount
                If countries = "" Then
                    countries = .Range("I" & Z).Value
                Else
                    countries = countries & ", " & .Range("I" & Z).Value
                End If
            Next Z
        End With
    End With
     Sheets("Sheet3").Cells(count, 7).Value = countries
End If
count = count + 1
Next v
'**  Testing block              **
Sheets("Sheet3").Columns("A:I").AutoFit
MsgBox "End loop"
                                            

The code below is only semi-tested but it should give you the idea of how to loop through the visible data of an AutoFiltered Range. You can't use code like "For r = 2 to Rows.Count" because the code stops after the first non contiguous row. However,
you can use For Each loop to loop through the rows and get the row number from there.
An explanation of the code to set rngVisible. (Note that a space and underscore at the end of a line is a line break in an otherwise single line of code.)
With .AutoFilter.Range   This is the entire AutoFilter Range (Includes column headers, visible and non visible rows)
 .Offset(1, 0)     Moves down one row off the column headers but now includes an additional row at the bottom below the data. (Still includes visible and non visible rows)
 .Resize(.Rows.Count - 1, .Columns.Count)     Removes the additional row due to Offset (Still includes visible and non visible rows)
.SpecialCells(xlCellTypeVisible)      Only include the visible rows.
    Sheets("Sheet1").Activate
    For Each v In dict.keys
        countries = ""
        If dict.Item(v) > 1 Then
            With ActiveSheet
                Set rnData = .UsedRange
                With rnData
                    .AutoFilter Field:=1, Criteria1:=v
                End With
                'Note that AutoFilter.Range is an inbuilt object variable _
                for the entire range covered by the AutoFilter
                With .AutoFilter.Range
                    'Following tests if any rows (other than column header) are visible _
                    in the AutoFilter.Range.  If > 1 then more than just column headers. _
                    Attempting to set the rngVisible will error if not at least one row _
                    of visible data.
                    If .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
                        'Assign the visible data to a range variable
                        Set rngVisible = .Offset(1, 0) _
                                   .Resize(.Rows.Count - 1, .Columns.Count) _
                                   .SpecialCells(xlCellTypeVisible)
                    Else
                        MsgBox "No visible data. Procesing terminated."
                        'Left for you to handle what you want to do if the _
                         filter does not exist in the data and no visible rows present
                        Exit Sub
                    End If
                End With
                'Loop through the rows of rngVisible
                'and get the row numbers
                For Each rngRow In rngVisible.Rows
                    Z = rngRow.Row
                    If countries = "" Then
                       countries = .Range("I" & Z).Value
                    Else
                       countries = countries & ", " & .Range("I" & Z).Value
                    End If
                Next rngRow
            End With
        End If
    Next v
Regards, OssieMac

Similar Messages

  • I have forgotten the answers to my security questions, how do I retrieve them?

    HELP... I have forgotten my answers to my security questions, how do I retrieve them?

    Hi,
    Since I originally posted that info APple have changed the page.
    There are less Menu items but in Password and Security I get shown the Security Questions.
    However rather then showing me the possible response it now want me to fill them in.
    It also shows  my recovery email (Shown in a partial format but enough detail so I know which Account it is) if I have forgotten the answers to the Questions.
    IF I fill in the Secruity Questions answers then the pages to what I had previously described.
    I can edit the recovery email address, change the Questions and Answers and even change my date of birth.
    7:20 PM      Friday; November 30, 2012
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Mountain Lion 10.8.2)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • How can I retrieve imessages after I restored my iphone to factory settings but didn't back up prior to restore?

    How can I retrieve imessages after I restored my iphone 4 to factory setting and didn't back up prior to restore?

    If you synch your phone to your computer via itunes,it performs a backup prior to synching. You can check by luanching itunes select preferences>devices,all backups should be shown there. If in fact there is a backup of your phone listed then do a restore of that back up.

  • HT201363 forgot my answers to my security questions how can i retrieve them

    forgot my answers to my security questions how can i retrieve them

    You need to ask Apple to reset your security questions; this can be done by phoning AppleCare and asking for the Account Security team, or clicking here and picking a method, or if your country isn't listed in either article, filling out and submitting this form.
    They wouldn't be security questions if they could be bypassed without Apple verifying your identity.
    (106241)

  • TS4009 how do you retrieve information after the system has been reset to default

    how do you retrieve information after the system has been reset to default?

    From a backup on itunes or icloud, assuming you have made backups.  Connect to itunes and in the first tab for your device, choose to perform a restore.

  • How can I retrieve values from integer array in sqlplus?

    I'm trying to write a query against OEM grid tables to come up with the result to show all scheduled backup jobs, in OEM grid, there is a table sysman.mgmt_job_schedule, one of the column DAYS is defined as TYPE SYSMAN.MGMT_JOB_INT_ARRAY AS VARRAY(5000) OF INTEGER,
    if I do select days from mgmt_job_schedule, it returns something like (2,3,4,5,,,,,,...), I want to retrieve the digits and translate them into Monday-Sunday in combination of other columns, but I'm new in varray, I don't know how can I retrieve the values in sqlplus, can you guys help me on that, My query is as follows, I got all the jobs I wanted already, just need to interpret on which day (week day) it is scheduled.
    Thanks
    select JOB_NAME, JOB_OWNER,job_type, mjs.START_TIME, DECODE(mjs.frequency_code,
    1, 'Once', 2, 'Interval', 3, 'Daily', 4, 'Weekly',
    5, 'Day of Month', 6, 'Day of Year', mjs.frequency_code) "FREQUENCY",
    mjs.days
    from mgmt_job mj, MGMT_JOB_SCHEDULE mjs
    where mj.SCHEDULE_ID=mjs.SCHEDULE_ID
    and mj.job_type='OSCommand'
    and mjs.Frequency_code in (3,4)
    and mj.is_library =0

    select job_name, job_owner, job_type, mjs.start_time,
               decode (
                    mjs.frequency_code,
                    1, 'Once',
                    2, 'Interval',
                    3, 'Daily',
                    4, 'Weekly',
                    5, 'Day of Month',
                    6, 'Day of Year',
                    mjs.frequency_code
                    "FREQUENCY", mjs.days, column_value
      from mgmt_job mj, mgmt_job_schedule mjs, table (nvl(days,sysman.mgmt_job_int_array(1,2,3,4,5,6,7)))
    where       mj.schedule_id = mjs.schedule_id
               and mj.job_type = 'OSCommand'
               and mjs.frequency_code in (3, 4)
               and mj.is_library = 0you may need to tweak the values in sysman.mgmt_job_int_array: use less or other values or simply put them null ....

  • How to change CUBE properies after create

    Hi,
    I am using AWM 102020A, I have created a CUBE and now want to go back and change some of the implementation details , is it possible to change :-
    Tab -> Implementation Details
    1. Order of dimensions
    2. Sparsity checkbox
    3. Partition Details
    Tab -> Cache
    1. Turn on session cache if checked off.
    Seems these are locked down after create, how can I change these details.
    Thanks for any help,
    Brandon

    Since you are you using the 10.2.0.2 version of AWM I suppose the database version you are using is also 10.2.0.2 or below.
    So to my knowledge the answer is no.
    If you are on the 10.2.0.3 version you have some more options because of the integrated sparsity advisor. Then you would have had the opportunity to recreate the cube. I have never tested the actual recreate function, but I've tested the sparsity advisor and saw that I could change if the cube was to be compressed, what dimension to be sparse etc.
    Seems like to have to have the 10.2.0.3 version of the database for this to work.
    regards Ragnar

  • Issue on condition value after creating PO using bapi_po_create1

    Hi ,
    I am passing condition value as 45.55  to Create PO using bapi_po_create1,
    but after Creating PO, But Condition Value reflecting ME23N as   4,555.00.
    Kindly Provide any solution if you have

    Hi ,
    I am passing condition value as 45.55  to Create PO using bapi_po_create1,
    but after Creating PO, But Condition Value reflecting ME23N as   4,555.00.
    Kindly Provide any solution if you have

  • HT1386 how do I retrieve contacts after syncing iphone?

    How do I retrieve phone contacts after syncing iphone4 with the lastest itunes?

    You sync them back to the phone from whatever contact manager or cloud service you've been syncing them with...

  • How do I retrieve tags after transfer to new computer.

    Have a PC.  HP Microsoft 7.  I undated to Elements 12 then transferred to new computer.  The pictures transferred fine  (20,000)  The tags only partly transferred and the symbols are so small  I can't read them.  I now have Elements 11 in my new computer.  I don't remember why.  How do I retrieve my tags.  Thanks,  Marilyn  509-547 5167

    Your personal information is in the profile folder. See: http://support.mozilla.com/en-US/kb/Profiles#How_to_find_your_profile
    You may also need this: http://kb.mozillazine.org/Show_hidden_files_and_folders
    When copying data from your OLD profile to your NEW profile, copy individual FILES (some require more than 1 FILE). DO NOT copy the entire OLD PROFILE folder; it will not work.
    See: [[Recovering important data from an old profile]]

  • How to change field values AFTER Inbound IDOC Posted successfully

    Hi SAP Experts,
    In my project I receive the inbound IDOC PORDCR05 from PI and posted as an Purchase Order in ECC.
    I create the Z process code and Z function module (which is a copy version of IDOC_INPUT_PORDCR) and complete all the necessary configuration steps. It works perfectly.
    My problem is: I have to  collect some inbound idocs (that satisfied some criteria) and change the value of field EKPO-TXJCD and EKKN-KOSTL of the PO AFTER  it posted successfully (means the purchase order is created and save in database).
    How can I do this? I've try to put the logic code in Z function module, but it does not work, since at that time, the Inbound IDOC is not updated to the database yet.
    Aprreciate your advise.
    Regards,
    Elaine.

    Hi Elaine ,
    as per your cretiria pick the idocs and take created PO# from status 53 & use the BAPI (BAPI_PO_CHANGE) to change the neccessary values in the PO. We can't reprocess those idocs again.
    Reddy

  • How to change UDF value in created A/R Invoice or A/P Good Receipt PO?

    I have created my UDFs  in Marketing Document Rows.
    After I've added some documents such as A/R Invoice or Good Receipt PO , I want to change my UDFs value for sometime. But  B1 don't let me do that. I know and understand the reason why we can't change this rows data. But I want to change my UDFs  only , so it don't effect any other things.
          How can I do this? or Can SDK help me?
    thx

    You can change with such statement :
    ObjInv.Lines.UserFields.Fields.Item("U_FieldName").Value = "123"
    Edited by: Riny Liu on Mar 17, 2008 5:39 PM

  • AIX 5.2 : how to pass password value while creating a user on AIX server

    Hi ,
    Test connection is successful with AIX server , I can successfully create a user on AIX server, with defualt password.
    I am not passing the any password value still some default value is being populated for the user...
    In AIX while creating the user , use get force to set the password...
    But while configuring the schema for AIX adapter ...if password attribute is given then it will give the error
    as invalid attribute...while creating a user if password value pass...
    how to set the password for the user..what attribute need to set for the password .
    thanks ..

    The default password might be the IdM account password of the user you are trying to provision. You don;t need to keep password in the resource schema. Just set password.password and password.confirmPassword and select AIX resource for password reset. Check the workflow-form-views document for more information on password view.

  • How to changing char. values and create new lines in C_TH_DATA

    Hi experts,
    we need to distribute the cost of some sender costcenters to the corresponding receiver costcenters.
    We have already created a DSO and maintained this with the sender and receiver costcenter. We use this lookup table later in the execute method of our created planning function type to take the sender costcenter and distribute this to the corresponding receiver costcenters.
    I've already implemented an IP planning function based on planning function type for this process.
    At the end when I debug the method I see that this works fine. I give you an example:
    I have in my lookup table the following record:
    sender costcenter           receiver costcenter            distribution percent
    4711                                    4712                                    75
    4711                                    4713                                    25
    Based on those records in the lookup table I've to distribute the cost of sender costcenter to the receiver costcenters.
    Just imagine I would get this record from c_th_data:
    sender costcenter    costelement     value
           4711                 3000111         100
    I have to have the following result after running the exit planning function:
       costcenter    costelement     value
           4711                 3000111         100                   -> without changing
           4711                 8000111        -100
           4712                 8000111           75
           4713                 8000111           25
    When I debug the exit function I see in the execute method that c_th_data will be filled correctly. I see exactly the records that I want to see.
    But once the function is finished I don't see this result. I also checked the conversation
    Changing Char Value in IP C_TH_DATA
    but I can't understand what happens after my coding yet.
    Can anyone help me or give me an advice what could be the problem here?
    Thank you all in advance for your support.
    Kind regards,
    Ali

    Hi Ali,
    The planning function generates the records in delta mode. I am explaining the concept taking your example only:
    Records in cube before running PF:
    sender costcenter           receiver costcenter            distribution percent
    4711                                    4712                                    75
    4711                                    4713                                    25
    sender costcenter    costelement     value
           4711                 3000111         100
           4712                 3000111         100
           4713                 3000111         100
    The records that you need to generate from code(Previous ones need to be changed):
    sender costcenter    costelement     value
           4711                 3000111         000
           4712                 3000111         175
           4713                 3000111         125
    **Please note that you dont need to generate any corrections(delta records), you only need to generate the final values in the records and the PF will generate the delta's on its own. Also in this case you should see 3 Records Read, 0 Deleted, 3 Changed.
    Please let me know if you need any more clarification,
    Thanks,
    Puneet

  • How to pass table values in Create Bapi Wrapper

    Hi All,
           Am using create BAPI  Wrapper in that how to map the fields inside BAPI  Import Structure .
    Thanks&Regrads,
    Arun

    Hi,
    Am using standard RFC " QIBP_INSPCHAR_SETRESULT "  for creating result recording in SAP QM. And BAPI_INSPOPER_GETDETAIL for getdetail i want to create BAPI wrapper for these 2 i already created BAPI wrapper for get detail . I dont know how to create Create BAPI wrapper.
    In QIBP_INSPCHAR_SETRESULT am passing inupt
    INSPLOT      LIKE         QALS-PRUEFLOS
    INSPOPER     LIKE     QAPO-VORNR
    INSPCHAR     LIKE     QAMV-MERKNR
    INSPSAMPLE     LIKE     QASV-PROBENR
    CHAR_RESULT     LIKE     BAPI2045D2           
    so i want to know how i can pass    1 . CHAR_RESULT structrue values
                                                               2.  INSPLOT,INSPOPER,INSPCHAR again repting inside CHAR_RESULT so how to map these
                                                                    in SDOE_WB
    Pls explain how to create BAPI Wrapper for this and how to map details.

Maybe you are looking for