Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

filter column and put

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Filter column and put info into next column for celected cells

Filter column and put info into next column for celected cells

ResolvedVersion 2003

Elena has attended:
Excel VBA Intro Intermediate course

Filter column and put info into next column for celected cells

Hi,
I have a spreadsheet. I would like to filter on column 51 and select any rows begins with Dresden. (this part is OK). Then I would like to put text "From Dresden" for all selected cells into column 53. Unfilter.
Then filter on column 52, select begins with Dresden and put text "To Dresden" against selected cells into column 53.

Range "BC:BC" is wrong. Please help.

My MACRO is:

Sub Dresden_Margin()
' Dresden_Margin Macro

Selection.AutoFilter Field:=51, Criteria1:="=*dresden*", Operator:=xlAnd
Range("BC:BC").Select
ActiveCell.FormulaR1C1 = "DR From"
Range("BC:BC").Select
Selection.FillDown
Selection.AutoFilter Field:=51
Selection.AutoFilter Field:=52, Criteria1:="=*dresden*", Operator:=xlAnd
Range("BC").Select
ActiveCell.FormulaR1C1 = "DR To"
Range("BC").Select
Selection.FillDown
Selection.AutoFilter Field:=52
End Sub

RE: Filter column and put info into next column for celected cel

Hi Elena

Thanks for getting in touch. If your macro is just trying to write a phrase next to Dresden cells then something like this would suffice, doing away with the Autofilter:

Range("AY1").Select ' this relates to field 51, row 1 in your data

Do Until ActiveCell = ""

If InStr(1, ActiveCell, "dresden") Then
ActiveCell.Offset(0, 1) = "DR From"
End If

If InStr(1, ActiveCell.Offset(0, 1), "dresden") Then
ActiveCell.Offset(0, 1) = "DR To"
End If

ActiveCell.Offset(1, 0).Select

Loop

You will need to add Option Compare Text to the very top of your module to catch all variations of case, and you may need to adjust the values depending on the structure of your data, but the key functionality is there.

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Wed 13 Mar 2013: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Repeating headings on spreadsheets that print on more than one page

By default when you print a spreadsheet out and it prints on more than one page, the headings at the top and the side of the spreadsheet don't appear on all the pages following page 1.

To get Excel to repeat headings on all pages when printing, go to File - Page Setup - Sheet, then select the rows to repeat at the top of pages, and the columns to repeat at the side of pages by clicking on the red arrows at the right side of the two boxes under the 'Print titles' area. Then click OK.

If you view your spreadsheet in Print Preview, you should see the headings being repeated on each page.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.08 secs.