Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Adding values from two different worksheets from workbook

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(Interna l)")
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Adding values from two different worksheets from workbook

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(Interna l)")
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Adding values from two different worksheets from workbook

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 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(Interna l)")
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
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
Adding over 30 worksheets in a workbook -E New Users to Excel 4 December 30th 08 06:11 PM
Adding values for multiple worksheets ArenaNinja Excel Discussion (Misc queries) 3 June 3rd 06 12:48 AM
Adding values from several worksheets - would appreciate the help Greegan Excel Worksheet Functions 0 July 26th 05 11:29 PM
Adding values from previous worksheets firecord Excel Worksheet Functions 1 June 27th 05 09:59 AM
adding values across worksheets in a spreadsheet ed java Excel Worksheet Functions 1 April 14th 05 12:06 AM


All times are GMT +1. The time now is 04:59 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"