Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2008

Tip: Looking for answers? Try searching our database.

Macro help - selecting rows after custom filter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe - 12 Jan 2008 10:07 GMT
Hello

I have recorded a macro to automatically import a file and then run a number
of filters through it and to display the results in a separate worksheet.

I do not have any Visual Basic knowledge, so am just using the "record
macro" function. So far so good, but now I've run into a problem.

How do I edit my macro so that it can automatically replace the contents of
cells in a particular column in as many rows as are required?

EXAMPLE:

Let's say the macro runs a custom filter in Column X to show all the rows
which have a value of either "A" orf "B" in that column. Now, what I want
the macro to do is to automatically select all those rows and replace the
contents of all the cells in Column Y with the value "1".

How do I get the macro to select all the necessary rows given that the
number of rows will be different every week I run the macro?  That is, when
I record the macro and run the custom filter, it may truncate my list to 10
rows of data. When I then go to use the macro the following week on a newly
imported file, the truncated list may have 17 rows of data. The following
week, 5 rows of data, and so on.

I guess this gets down to Excel navigation and the ability to automatically
select only the displayed rows of a particular column.

I hope this all makes sense....?

Any help would be most appreciated!

Thanks,

Joe.
Ron de Bruin - 12 Jan 2008 10:39 GMT
Hi Joe

The example here copy all visible data to a new sheet
http://www.rondebruin.nl/copy5.htm#AutoFilter

We use
WS.AutoFilter.Range.Copy

But you only want to replace the data in one column on the destination sheet(existing sheet)
Am I correct

Let me know then I will help you

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> Hello
>
[quoted text clipped - 31 lines]
>
> Joe.
Joe - 12 Jan 2008 11:15 GMT
Hi Ron

Thank you for your help! Much appreciate it.

Yes, I only need to replace the data in one column. This seemed easy enough
at first, but then I realised that the number of rows will change each week.

Joe.

On 12/1/08 8:39 PM, in article ejIN5dQVIHA.4440@TK2MSFTNGP06.phx.gbl, "Ron
de Bruin" <rondebruin@kabelfoon.nl> wrote:

> Hi Joe
>
[quoted text clipped - 9 lines]
>
> Let me know then I will help you
Ron de Bruin - 12 Jan 2008 11:49 GMT
Hi Joe

Must go now but will reply this evening

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> Hi Ron
>
[quoted text clipped - 21 lines]
>>
>> Let me know then I will help you
Ron de Bruin - 12 Jan 2008 17:48 GMT
Hi Joe

You can run this macro on your new sheet

Maybe you want to clear column Y first so you only see the 1 if there is A or B in X
Let me know if you want that

Sub AutoFilterTest()
   Dim WS As Worksheet
   Dim WSNew As Worksheet
   Dim rng As Range
   Dim rng2 As Range

   With Application
       .ScreenUpdating = False
       .EnableEvents = False
   End With

   'Name of the worksheet with the data
   Set WS = ActiveSheet

   'Set filter range : All data in X
   Set rng = WS.Range("X1:X" & Rows.Count)

   'Firstly, remove the AutoFilter
   WS.AutoFilterMode = False

   rng.AutoFilter Field:=1, Criteria1:="=A", Operator:=xlOr, Criteria2:="=B"

   WS.AutoFilter.Range.Offset(0, 1).Value = 1

   'Close AutoFilter
   WS.AutoFilterMode = False

   With Application
       .ScreenUpdating = True
       .EnableEvents = True
   End With

End Sub

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> Hi Joe
>
[quoted text clipped - 25 lines]
>>>
>>> Let me know then I will help you
Alex Turner - 12 Jan 2008 14:54 GMT
> Hello
>
[quoted text clipped - 32 lines]
>
> Joe.

Try looking here:
http://nerds-central.blogspot.com/2008/01/excel-filter-report-scripting-
macro.html

Signature

http://nerds-central.blogspot.com/search/label/Baby%20Steps

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.