LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Formula to use in Macro

I'm trying to set up a macro to do things I normally do by hand, over 15 or
so tabs in a workbook on a monthly basis.

On each sheet, I sort the sheet according to three columns. Then I insert a
column at B. The formula I type by hand is
=IF(COUNTIF(A2:A30,A2)1,"Duplicate",""). Then I double click to fill down,
copy, paste values, and sort descending by that new column. Except that the
A30 changes each month!

I need to set up the macro so that I can reuse it each month on a new
workbook. Everything is the same, except the location of the last row of
information. I normally use
Selection.AutoFill Destination:=Range("B2:B" &
ActiveSheet.UsedRange.Rows.Count)
and that will auto fill to the last row of used data. But I don't know how
to incorporate that into the sort and the end of the range in the if countif
formula.
It looks like this in my macro:
Range("A1:K30").Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range( _
"G2"), Order2:=xlAscending, Key3:=Range("F2"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Range("B2").Select
ActiveCell.FormulaR1C1 = _
"=IF(COUNTIF(RC[-1]:R[28]C[-1],RC[-1])1,""Duplicate"","""")"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:B30")
Range("B2:B30").Select

Any help or tips for these two things would be most appreciated!!!!
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula in macro causes macro to fail KCK Excel Programming 2 February 8th 07 08:47 PM
Formula expected end of statement error, typing formula into cell as part of VBA macro [email protected] Excel Programming 1 July 20th 06 07:58 PM
Macro Formula Corey Excel Discussion (Misc queries) 1 February 4th 06 06:13 PM
formula or macro Kucey Excel Worksheet Functions 1 November 2nd 05 01:47 AM
Formula in macro help Biff Excel Programming 10 August 13th 05 06:13 AM


All times are GMT +1. The time now is 06:30 PM.

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

About Us

"It's about Microsoft Excel"