Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Unsure of my error?

I am trying to find matches for certain cells in my spreadsheet, and when a
match based on the criteria is found, i want to Sum the values of another
column together. Here is what I have, but it doesn't work properly. This is
returning significantly different values depending on how the sheet is
sorted, when in theory, it should work regardless of how the sheet is sorted!

Sub Addupifmatch()

For k = 2 To 10000
qty = Cells(k, "h")

For i = Cells(Rows.Count, "c").End(xlUp).Row To 2 Step -1
If Cells(i, "c") = "1" Then
GoTo 1
ElseIf IsEmpty(Cells(i, "c")) Then
GoTo 1
ElseIf Cells(i, "c") = Cells(k, "c") Then
qty = qty + Cells(i, "h")
Rows(i).Delete
Else
End If
1 Next
Cells(k, "h") = qty
Next
End Sub

The first two parts of the if statement are because i want to ignore a few
types of data. ANy help would be much appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Unsure of my error?

You do not need the first two parts of the If ...ElseIf statement. Unless
the criteria is met in the third part, it will ignore the other two
conditions anyhow. I think that adding the value property to your cell
references might solve the problem. Give it a try. If it does not work,
post back.

Sub Addupifmatch()

For k = 2 To 10000
qty = Cells(k, "h")

For i = Cells(Rows.Count, "c").End(xlUp).Row To 2 Step -1
If Cells(i, "c") .Value= Cells(k, "c") .ValueThen
qty = qty + Cells(i, "h").Value
Rows(i).Delete
End If
Next
Cells(k, "h") = qty
Next
End Sub



"Derek Johansen" wrote in message
...
I am trying to find matches for certain cells in my spreadsheet, and when a
match based on the criteria is found, i want to Sum the values of another
column together. Here is what I have, but it doesn't work properly. This
is
returning significantly different values depending on how the sheet is
sorted, when in theory, it should work regardless of how the sheet is
sorted!

Sub Addupifmatch()

For k = 2 To 10000
qty = Cells(k, "h")

For i = Cells(Rows.Count, "c").End(xlUp).Row To 2 Step -1
If Cells(i, "c") = "1" Then
GoTo 1
ElseIf IsEmpty(Cells(i, "c")) Then
GoTo 1
ElseIf Cells(i, "c") = Cells(k, "c") Then
qty = qty + Cells(i, "h")
Rows(i).Delete
Else
End If
1 Next
Cells(k, "h") = qty
Next
End Sub

The first two parts of the if statement are because i want to ignore a few
types of data. ANy help would be much appreciated!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Unsure of my error?

You must have some blank rows that is causing the problem. Try this code.

Sub Addupifmatch()

k = 2
LastRow = Cells(Rows.Count, "c").End(xlUp).Row
Do
qty = Cells(k, "h")
For i = LastRow To k Step -1
If Cells(i, "c") < "1" And _
Not IsEmpty(Cells(i, "c")) Then

If Cells(i, "c") = Cells(k, "c") Then
qty = qty + Cells(i, "h")
Rows(i).Delete
End If
End If
Next i
Cells(k, "h") = qty
k = k + 1
LastRow = Cells(Rows.Count, "c").End(xlUp).Row
Loop While k <= LastRow
End Sub

"Derek Johansen" wrote:

I am trying to find matches for certain cells in my spreadsheet, and when a
match based on the criteria is found, i want to Sum the values of another
column together. Here is what I have, but it doesn't work properly. This is
returning significantly different values depending on how the sheet is
sorted, when in theory, it should work regardless of how the sheet is sorted!

Sub Addupifmatch()

For k = 2 To 10000
qty = Cells(k, "h")

For i = Cells(Rows.Count, "c").End(xlUp).Row To 2 Step -1
If Cells(i, "c") = "1" Then
GoTo 1
ElseIf IsEmpty(Cells(i, "c")) Then
GoTo 1
ElseIf Cells(i, "c") = Cells(k, "c") Then
qty = qty + Cells(i, "h")
Rows(i).Delete
Else
End If
1 Next
Cells(k, "h") = qty
Next
End Sub

The first two parts of the if statement are because i want to ignore a few
types of data. ANy help would be much appreciated!

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
Unsure how to set up spreadsheet Carla Excel Discussion (Misc queries) 1 February 2nd 10 10:28 PM
Unsure what formula to use Finding_Facts_NC Excel Discussion (Misc queries) 8 January 23rd 08 10:01 PM
Unsure of which forumla to use ? Ben Excel Discussion (Misc queries) 3 December 16th 07 09:43 PM
Unsure of the Function, and How to Write It Jane Excel Worksheet Functions 3 August 20th 07 04:59 PM
Unsure about which functions to use Rich Excel Worksheet Functions 4 April 21st 05 10:37 PM


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