Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Sumif In A Macro


I have a worksheet with 20 sheets in it named Bic_Code1, Bic_Code2 etc.
I also have a sheet called CopyFromTo.

The Sheets are all the same size with the same number of rows and
columns.

Using Sheet Bic_Code1 as an example -

At the bottom of the sheet is a block of data that I want to copy to
the
CopyFromTo sheet, run a de dupe macro, then go to I1 of the CopyToFrom
Sheet and do the following calculation-
sumif(Bic_Code1("D6:D61"),CopyToFrom("D1"),sumif(B ic_Code1("I6:I61")

I then sort descending, by value and copy back to another area of
Bic_Code1.

Then I want to go to sheet Bic_Code2 and do the same and so on.

My macro works perfectly except for the sumif part.

I have identified the Bic_Code1 sheet using

WorksheetName = ("Bic_Code1")

When the macro loops around I have a second statement
WorksheetName = ActiveSheet.Name so that it knows it is now on
Bic_Code2

I tried every way I know of to get this macro to work for the sumif but
I get a type mismatch error. If I hover in step mode ShtNm is picking up
Bic_Code1 so it must be something else.

All help much appreciated.


Code:
--------------------
Dim CopyFromTo
Dim ShtNm

CopyFromTo = ("CopyFromTo")

ShtNm = WorksheetName

Range("I1").Select
With SumIf
Worksheet.Formula = SumIf(Sheets(ShtNm).Range("$D$6:$D$51"), Sheets(CopyFromTo).Range("E1"), Sheets(ShtNm).Range("$I$6:$I$51"))
End With

--------------------


--
Timbo
------------------------------------------------------------------------
Timbo's Profile: http://www.thecodecage.com/forumz/member.php?userid=24
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=40193

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Using Sumif In A Macro

Hi Timbo

In Excel 2003 I have created this:

Sub CreateSumIf()
Dim CopyFromTo As String
Dim ShtNm As String
Dim sFormula As String

CopyFromTo = ("CopyfromTo")

ShtNm = WorksheetName
Range("I1").Select

sFormula = "=SumIf(" & ShtNm & "!$D$6:$D$51, " & _
CopyFromTo & "!E1," & ShtNm & "!$I$6:$I$51)"

Range("I1").Formula = sFormula
End Sub

HTH,

Wouter
Reply
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
Sumif Macro Rick Excel Programming 4 July 29th 08 04:20 AM
Macro with sumif orquidea Excel Discussion (Misc queries) 4 December 7th 07 02:15 AM
macro with sumif orquidea Excel Worksheet Functions 1 December 5th 07 08:02 PM
How do I sum across rows in a macro? SumIf? future Excel Programming 8 February 5th 04 11:56 PM
sumif formula in a macro paul[_13_] Excel Programming 0 January 23rd 04 03:51 PM


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

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

About Us

"It's about Microsoft Excel"