Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-29-2015, 06:47 AM
saurabhlotankar saurabhlotankar is offline Process Automation Windows XP Process Automation Office 2010 32bit
Novice
Process Automation
 
Join Date: May 2015
Posts: 29
saurabhlotankar is on a distinguished road
Default Process Automation

Hi Folks,

I hope you all are doing good.

I badly need to design a macro to automate a process which i am doing manually and taking hell lot of time.

I have attached an excel sheet.



Please find below the pointers that i need to do in it.

  • open the attached file.
  • Go to sheet3, where you will find a table at the top with headers code, name and country names etc(A1:J11)
  • Whereever there is "yes" mentioned in that table i want country name and code(mentioned in column A). i want to list that country name and code from row A14 onwards. Challenge here is, i want country name as many times as there is "yes" in above table.
  • To make it simple to understand this time i have copied such data manually from cell A14 onwards. E.g. if you look at United Kingdom, there are 2 yes in above table, so i took United kingdom twice from cell A14 and infront of that i also took code of those 2 yes from above table(A7 & A10)
Here ends the first part of the macro.


lets move to 2nd part.

  • In C & D column of sheet3 you will find cells with Filter Criteria headers. I have formulated that. No need to touch them. What I want to do is, use them as a filter criteria in Sheet1 column P
  • But the filter should be for Deselecting the values this time.
  • For example, in sheet3, cell C14 there is value "UK:06:" , so in sheet1 column P I want to apply filter and deselect rows which have value "UK:06:". and in same way it should deselect all rows which have values in C & D column filter criteria
  • Ideally Code should automatically find unique vales from filter criteria, and then apply filter in sheet 1, because all the values are repeating again and again.
  • Once the filter is applied, sheet 1 should have all rows except the rows which does not have values mentioned filter criteria in sheet3(like UK:06:, UK:07:, NE:06:. NE:07: etc)


It would be great if you can assist me on this.


Thanks,
Attached Files
File Type: xlsx Filter V1.xlsx (27.2 KB, 24 views)
Reply With Quote
  #2  
Old 05-30-2015, 09:01 AM
saurabhlotankar saurabhlotankar is offline Process Automation Windows XP Process Automation Office 2010 32bit
Novice
Process Automation
 
Join Date: May 2015
Posts: 29
saurabhlotankar is on a distinguished road
Default

Any luck guys?
Reply With Quote
  #3  
Old 05-30-2015, 10:18 AM
charlesdh charlesdh is offline Process Automation Windows 7 32bit Process Automation Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

Not that I have a solution. But, from all of the help you received in your previous post it would appear that you should be able to write the code yourself.
Reply With Quote
  #4  
Old 05-30-2015, 10:37 PM
saurabhlotankar saurabhlotankar is offline Process Automation Windows XP Process Automation Office 2010 32bit
Novice
Process Automation
 
Join Date: May 2015
Posts: 29
saurabhlotankar is on a distinguished road
Default

Am trying my best but not working out. I apologize if am troubling u guys.
Reply With Quote
  #5  
Old 05-31-2015, 04:19 PM
charlesdh charlesdh is offline Process Automation Windows 7 32bit Process Automation Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

I noticed that in columns "C" and "D" starting at row 14 have duplicate values.
That is the "UK" has "UK:06: UK:07" 2 times. This I believe is predicated on the nr. of times a country is listed. If this is always the case the you would need to set the filter in sheet1 <> "UK:06: UK:07".
My question to you is will the data starting in row 14 column "C", "D" use the same pattern?
That is if row 14 has "UK:06: UK:07". Will row 15 be the same?
Also in sheet3 you have 2 different codes that = "Yes" but no correlation to this is in sheet1.
So I would assume that for sheet1 you would only need the filter only 1 time for the the data that <> "UK:06: UK:07".

Now once you set the filter for sheet1 what do you do with the filtered data.
Reply With Quote
  #6  
Old 05-31-2015, 05:47 PM
excelledsoftware excelledsoftware is offline Process Automation Windows 8 Process Automation Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

Looks like Charles has a handle on this but my question is the filter part. Do you want any row in sheet 1 to be hidden if it contains any of the values in columns C or D on Sheet 3? That is the only way I can see this doing what you want. If that is what you are looking for let us know. Charles I have the idea on how to do this but since you are first on scene I will only provide it if you need.

Thanks
Reply With Quote
  #7  
Old 05-31-2015, 05:55 PM
charlesdh charlesdh is offline Process Automation Windows 7 32bit Process Automation Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

exceledsoftware,

I've been looking at this, but have not found a solution. If you have one please share it with us.
Reply With Quote
  #8  
Old 05-31-2015, 07:25 PM
excelledsoftware excelledsoftware is offline Process Automation Windows 8 Process Automation Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

Ok here is what I was able to put together quickly. Now I have the filter actually hiding the rows rather than filtering it. This is slightly different. In the event you need to actually apply the filter I would advise having a column get a value like a 1 in column DQ then apply the filter to DQ.
Code:
Option Explicit

Sub CheckYesValues()
  'Looks at each header in sheet 3 and then identifies if it has a yes.
  'If it does the value is placed into the resultrow.
  Dim wb As Workbook, cws As Worksheet, CheckRow As Long, ResultRow As Long
  Dim Header As String, CheckCol As Integer, LastCol As Integer, LastRow As Long
  Dim Code As String, CheckString As String, rws As Worksheet
  Dim FilterString As String, FilterGroup As Variant, v As Variant
  
  
  'Set the references
  Set wb = ThisWorkbook
  Set cws = wb.Worksheets("Sheet3")
  Set rws = wb.Worksheets("Sheet1")
  LastCol = cws.Range("A1").End(xlToRight).Column
  LastRow = 11 'Hard coded for now
  ResultRow = 14
  
  
  'Perform the checks and print results
  For CheckCol = 3 To LastCol
    Header = cws.Cells(1, CheckCol).Value
    For CheckRow = 2 To LastRow
      Code = cws.Range("A" & CheckRow).Value
      CheckString = LCase(cws.Cells(CheckRow, CheckCol).Value)
      If CheckString = "yes" Then 'print result
        cws.Range("A" & ResultRow).Value = Header
        cws.Range("B" & ResultRow).Value = Code + 0
        ResultRow = ResultRow + 1
      End If
    Next CheckRow
  Next CheckCol
  
  'Hold the values in a string to check
  For CheckRow = 14 To ResultRow - 1 ' Again hardcoded for now
    CheckString = cws.Range("C" & CheckRow).Value
    If InStr(1, FilterString, CheckString) = 0 Then
      FilterString = FilterString & CheckString & ","
    End If
    CheckString = cws.Range("D" & CheckRow).Value
    If InStr(1, FilterString, CheckString) = 0 Then
      FilterString = FilterString & CheckString & ","
    End If
  Next CheckRow
  'Remove final comma
  If Right(FilterString, 1) = "," Then
    FilterString = Mid(FilterString, 1, Len(FilterString) - 1)
  End If
  'Split into array to use
  FilterGroup = Split(FilterString, ",")
   
  '****************************************
  'Now do the 2nd part of the macro
  LastRow = rws.Range("B1").End(xlDown).Row + 1
  'Make sure all are showing first
  For CheckRow = 2 To LastRow
    If rws.Range("A" & CheckRow).EntireRow.Hidden = True Then
      rws.Range("A" & CheckRow).EntireRow.Hidden = False
    End If
  Next CheckRow
  
  'Now check
  For CheckRow = 2 To LastRow
    CheckString = rws.Range("P" & CheckRow).Value
    'Check if its in there
    For Each v In FilterGroup
      If InStr(1, CheckString, v) Then
        rws.Range("A" & CheckRow).EntireRow.Hidden = True
        Exit For
      End If
    Next v
  Next CheckRow
  
  MsgBox "done"
  
End Sub
As with all code, backup your work and save before running.

Let me know if this is a good starting point, the solution or if you need anything else.

Thanks
Reply With Quote
  #9  
Old 06-01-2015, 10:26 AM
charlesdh charlesdh is offline Process Automation Windows 7 32bit Process Automation Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

exceledsoftware,

Your code is different form what I was trying to with no luck.
I was attempting to use a filter using an "Array". But, that proved to be a little difficult.
Hiding the rows as you did looks good. But, what does the user want to do with the data after the code runs?
Does the user want to do each country separately or as your code does at the same time.
Also the user did not provide data in sheet1 that was in sheet3.
Perhaps the user will give us more information as to how they want to handle this.
Reply With Quote
  #10  
Old 06-03-2015, 07:30 AM
saurabhlotankar saurabhlotankar is offline Process Automation Windows XP Process Automation Office 2010 32bit
Novice
Process Automation
 
Join Date: May 2015
Posts: 29
saurabhlotankar is on a distinguished road
Default

Thanks Guys for your help. Sorry for the delayed reply.

I was doing it through formulas. But i guess macro version is faster.

Thanks,
Both of you.
Reply With Quote
  #11  
Old 06-03-2015, 05:50 PM
excelledsoftware excelledsoftware is offline Process Automation Windows 8 Process Automation Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

Hopefully it is working. If so please feel free to mark this thread as solved. Let me know if there is anything else I can help with.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Process Automation Outlook process not closing Alan.bailey Outlook 2 02-12-2015 08:56 AM
Automation Process of Schedule Report Output and Report Check Score Card ! ozman86 Word VBA 1 11-19-2014 11:52 PM
Process Automation Excel -> PowerPoint multiple presentations - process automation wstach Excel Programming 2 03-18-2014 06:20 AM
automating a repetitive process vthomeschoolmom Excel Programming 1 02-28-2012 07:41 PM
Automating daily process dreww2 Outlook 0 06-28-2011 07:25 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft