PC Review


Reply
Thread Tools Rate Thread

Adding values from two different worksheets from workbook

 
 
Mahadevan Swamy
Guest
Posts: n/a
 
      5th Jul 2007
Hi,

Here is the VB code which I have been working on:

Function Defects(MyMonth As Date, Dept As String, DefectCode As
String)

'Windows("Input.xls").ActivateSheets("Customer Returns
(External)").Activate Defects = 0
With Workbooks("Input.xls").Sheets("Customer Returns (External)")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Defects = 0
For RowCount = 3 To LastRow

If (Month(.Cells(RowCount, "A")) = Month(MyMonth)) Then
If (.Cells(RowCount, "E") = Left(Dept, 2)) Then
If (.Cells(RowCount, "F") = DefectCode) Then
If (IsEmpty(.Cells(RowCount, "J"))) Then
If (IsEmpty(.Cells(RowCount, "I"))) Then
Defects = Defects + .Cells(RowCount, "H")
Else
Defects = Defects + .Cells(RowCount, "I")
End If
Else
Defects = Defects + .Cells(RowCount, "J")
End If
End If
End If
End If
Next RowCount
End With

With Workbooks("Input.xls").Sheets("LineReturns(Internal)")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

For RowCount = 3 To LastRow

If (Month(.Cells(RowCount, "A")) = Month(MyMonth)) Then
If (.Cells(RowCount, "E") = Left(Dept, 2)) Then
Defects = Defects + .Cells(RowCount, "C")
End If
End If

Next RowCount

End With
End Function


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

My objective is to go to customer returns worksheet, check for
conditions if it is the same month, dept, and defect code and then
return the quantity of defects. Then go to line returns worksheet,
check for conditions if it is same month, dept and defect code and
return the quantity of defects. Then the returned value that I must
get is the value from customer defects + value from line returns.

I have tried all means to fix this but it is not working. Can anybody
find the problem with this code. Thanks

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      5th Jul 2007
I've told you before, you can't activate another worksheet from inside a
function

'Windows("Input.xls").ActivateSheets("Customer Returns(External)").Activate

Defects = 0

"Mahadevan Swamy" wrote:

> Hi,
>
> Here is the VB code which I have been working on:
>
> Function Defects(MyMonth As Date, Dept As String, DefectCode As
> String)
>
> 'Windows("Input.xls").ActivateSheets("Customer Returns
> (External)").Activate Defects = 0
> With Workbooks("Input.xls").Sheets("Customer Returns (External)")
> LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
> Defects = 0
> For RowCount = 3 To LastRow
>
> If (Month(.Cells(RowCount, "A")) = Month(MyMonth)) Then
> If (.Cells(RowCount, "E") = Left(Dept, 2)) Then
> If (.Cells(RowCount, "F") = DefectCode) Then
> If (IsEmpty(.Cells(RowCount, "J"))) Then
> If (IsEmpty(.Cells(RowCount, "I"))) Then
> Defects = Defects + .Cells(RowCount, "H")
> Else
> Defects = Defects + .Cells(RowCount, "I")
> End If
> Else
> Defects = Defects + .Cells(RowCount, "J")
> End If
> End If
> End If
> End If
> Next RowCount
> End With
>
> With Workbooks("Input.xls").Sheets("LineReturns(Internal)")
> LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
>
> For RowCount = 3 To LastRow
>
> If (Month(.Cells(RowCount, "A")) = Month(MyMonth)) Then
> If (.Cells(RowCount, "E") = Left(Dept, 2)) Then
> Defects = Defects + .Cells(RowCount, "C")
> End If
> End If
>
> Next RowCount
>
> End With
> End Function
>
>
> ------------------------------------------------------------------
>
> My objective is to go to customer returns worksheet, check for
> conditions if it is the same month, dept, and defect code and then
> return the quantity of defects. Then go to line returns worksheet,
> check for conditions if it is same month, dept and defect code and
> return the quantity of defects. Then the returned value that I must
> get is the value from customer defects + value from line returns.
>
> I have tried all means to fix this but it is not working. Can anybody
> find the problem with this code. Thanks
>
>

 
Reply With Quote
 
Mahadevan Swamy
Guest
Posts: n/a
 
      5th Jul 2007
So is there a way to solve this by putting the line returns data and
customer returns data in one worksheet?

On Jul 5, 3:28 pm, Joel <J...@discussions.microsoft.com> wrote:
> I've told you before, you can't activate another worksheet from inside a
> function
>
> 'Windows("Input.xls").ActivateSheets("Customer Returns(External)").Activate
>
> Defects = 0
>
> "Mahadevan Swamy" wrote:
> > Hi,

>
> > Here is the VB code which I have been working on:

>
> > Function Defects(MyMonth As Date, Dept As String, DefectCode As
> > String)

>
> > 'Windows("Input.xls").ActivateSheets("Customer Returns
> > (External)").Activate Defects = 0
> > With Workbooks("Input.xls").Sheets("Customer Returns (External)")
> > LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
> > Defects = 0
> > For RowCount = 3 To LastRow

>
> > If (Month(.Cells(RowCount, "A")) = Month(MyMonth)) Then
> > If (.Cells(RowCount, "E") = Left(Dept, 2)) Then
> > If (.Cells(RowCount, "F") = DefectCode) Then
> > If (IsEmpty(.Cells(RowCount, "J"))) Then
> > If (IsEmpty(.Cells(RowCount, "I"))) Then
> > Defects = Defects + .Cells(RowCount, "H")
> > Else
> > Defects = Defects + .Cells(RowCount, "I")
> > End If
> > Else
> > Defects = Defects + .Cells(RowCount, "J")
> > End If
> > End If
> > End If
> > End If
> > Next RowCount
> > End With

>
> > With Workbooks("Input.xls").Sheets("LineReturns(Internal)")
> > LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

>
> > For RowCount = 3 To LastRow

>
> > If (Month(.Cells(RowCount, "A")) = Month(MyMonth)) Then
> > If (.Cells(RowCount, "E") = Left(Dept, 2)) Then
> > Defects = Defects + .Cells(RowCount, "C")
> > End If
> > End If

>
> > Next RowCount

>
> > End With
> > End Function

>
> > ------------------------------------------------------------------

>
> > My objective is to go to customer returns worksheet, check for
> > conditions if it is the same month, dept, and defect code and then
> > return the quantity of defects. Then go to line returns worksheet,
> > check for conditions if it is same month, dept and defect code and
> > return the quantity of defects. Then the returned value that I must
> > get is the value from customer defects + value from line returns.

>
> > I have tried all means to fix this but it is not working. Can anybody
> > find the problem with this code. Thanks



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
summary values across worksheets within the same workbook Gordon Microsoft Excel Worksheet Functions 2 30th Apr 2010 11:40 PM
Adding over 30 worksheets in a workbook -E Microsoft Excel New Users 4 30th Dec 2008 06:11 PM
Copy Values Between Worksheets in same Workbook =?Utf-8?B?Sm9lIEsu?= Microsoft Excel Programming 3 8th Oct 2007 11:30 AM
How do I sum values from different worksheets within one workbook. =?Utf-8?B?bWFzdGVyIGdhcmRlbmVy?= Microsoft Excel Worksheet Functions 1 28th Jan 2005 07:19 PM
adding new worksheets to a workbook =?Utf-8?B?TWFyeV9D?= Microsoft Excel Programming 1 29th Mar 2004 02:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:57 AM.