Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default ForEach procedure adding values

Hi,
I've done a ForEach procedure that updates an output list
(based on names in column A, sheet Output) based on a
database (names in column A and values in column B, Sheet
Input).

If there are two identical names in the "database", I want
to add those values in the Output sheet for that name.
(Now I only get the last number in the database)

I appreciate any suggestion how to solve this?

Thanks!
Mats Westin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ForEach procedure adding values

Dim rng as Range, rng1 as Range, cell as Range
Dim res as variant
With Worksheets("Output")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
With Worksheets("Input")
set rng1 = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
for each cell in rng
res = Application.Match(cell,rng1,0)
if not iserror(res) then
cell.offset(0,1).Value = _
rng1(res).Offset(0,1).Value
End if
Next

--
Regards,
Tom Ogilvy

"Mats Westin" wrote in message
...
Hi,
I've done a ForEach procedure that updates an output list
(based on names in column A, sheet Output) based on a
database (names in column A and values in column B, Sheet
Input).

If there are two identical names in the "database", I want
to add those values in the Output sheet for that name.
(Now I only get the last number in the database)

I appreciate any suggestion how to solve this?

Thanks!
Mats Westin



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default ForEach procedure adding values

Thanks Tom!

Unfortunately this does not solve the problem! If there
are several items in column A in the input sheet, I want
the values summarised for those items in the output sheet
(under the same item name). Your suggestion results in
taking the first item that match from the input sheet
instead of adding all items with the same name.

Rgds,
Mats

-----Original Message-----
Dim rng as Range, rng1 as Range, cell as Range
Dim res as variant
With Worksheets("Output")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End

(xlup))
End With
With Worksheets("Input")
set rng1 = .Range(.Cells(1,1),.Cells(rows.count,1).End

(xlup))
End With
for each cell in rng
res = Application.Match(cell,rng1,0)
if not iserror(res) then
cell.offset(0,1).Value = _
rng1(res).Offset(0,1).Value
End if
Next

--
Regards,
Tom Ogilvy

"Mats Westin" wrote

in message
...
Hi,
I've done a ForEach procedure that updates an output

list
(based on names in column A, sheet Output) based on a
database (names in column A and values in column B,

Sheet
Input).

If there are two identical names in the "database", I

want
to add those values in the Output sheet for that name.
(Now I only get the last number in the database)

I appreciate any suggestion how to solve this?

Thanks!
Mats Westin



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ForEach procedure adding values

Well, your description was ambiguous about that issue - at least to me.

Easily rectified.

Dim rng as Range, rng1 as Range, cell as Range
Dim res as variant
With Worksheets("Output")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
With Worksheets("Input")
set rng1 = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
for each cell in rng
cell.offset(0,1).Value = _
application.Sumif(rng1,cell.value,rng1.offset(0,1) )
Next

--
Regards,
Tom Ogilvy


"Mats" wrote in message
...
Thanks Tom!

Unfortunately this does not solve the problem! If there
are several items in column A in the input sheet, I want
the values summarised for those items in the output sheet
(under the same item name). Your suggestion results in
taking the first item that match from the input sheet
instead of adding all items with the same name.

Rgds,
Mats

-----Original Message-----
Dim rng as Range, rng1 as Range, cell as Range
Dim res as variant
With Worksheets("Output")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End

(xlup))
End With
With Worksheets("Input")
set rng1 = .Range(.Cells(1,1),.Cells(rows.count,1).End

(xlup))
End With
for each cell in rng
res = Application.Match(cell,rng1,0)
if not iserror(res) then
cell.offset(0,1).Value = _
rng1(res).Offset(0,1).Value
End if
Next

--
Regards,
Tom Ogilvy

"Mats Westin" wrote

in message
...
Hi,
I've done a ForEach procedure that updates an output

list
(based on names in column A, sheet Output) based on a
database (names in column A and values in column B,

Sheet
Input).

If there are two identical names in the "database", I

want
to add those values in the Output sheet for that name.
(Now I only get the last number in the database)

I appreciate any suggestion how to solve this?

Thanks!
Mats Westin



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default ForEach procedure adding values

Thanks Tom!
I know that you helped me before and I'm sorry for not
beeing clear enougth to begin with!
Now it works exactly like I want it to!
Thanks a lot!
Rgds,
Mats W
-----Original Message-----
Well, your description was ambiguous about that issue -

at least to me.

Easily rectified.

Dim rng as Range, rng1 as Range, cell as Range
Dim res as variant
With Worksheets("Output")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End

(xlup))
End With
With Worksheets("Input")
set rng1 = .Range(.Cells(1,1),.Cells(rows.count,1).End

(xlup))
End With
for each cell in rng
cell.offset(0,1).Value = _
application.Sumif(rng1,cell.value,rng1.offset(0,1) )
Next

--
Regards,
Tom Ogilvy


"Mats" wrote in

message
...
Thanks Tom!

Unfortunately this does not solve the problem! If there
are several items in column A in the input sheet, I want
the values summarised for those items in the output

sheet
(under the same item name). Your suggestion results in
taking the first item that match from the input sheet
instead of adding all items with the same name.

Rgds,
Mats

-----Original Message-----
Dim rng as Range, rng1 as Range, cell as Range
Dim res as variant
With Worksheets("Output")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End

(xlup))
End With
With Worksheets("Input")
set rng1 = .Range(.Cells(1,1),.Cells

(rows.count,1).End
(xlup))
End With
for each cell in rng
res = Application.Match(cell,rng1,0)
if not iserror(res) then
cell.offset(0,1).Value = _
rng1(res).Offset(0,1).Value
End if
Next

--
Regards,
Tom Ogilvy

"Mats Westin"

wrote
in message
...
Hi,
I've done a ForEach procedure that updates an output

list
(based on names in column A, sheet Output) based on a
database (names in column A and values in column B,

Sheet
Input).

If there are two identical names in the "database", I

want
to add those values in the Output sheet for that

name.
(Now I only get the last number in the database)

I appreciate any suggestion how to solve this?

Thanks!
Mats Westin


.



.

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
Stop a Procedure from another procedure Ayo Excel Discussion (Misc queries) 1 October 30th 08 01:42 AM
Adding numerical values based on multiple values in another column Kazmaniac Excel Worksheet Functions 6 April 4th 07 08:53 PM
simplify procedure to get rid of 0 error values in a spreadsheet Frederic Excel Worksheet Functions 1 February 8th 06 04:47 AM
Dynamic Values in Procedure Dave Peterson[_3_] Excel Programming 0 July 19th 03 03:12 AM


All times are GMT +1. The time now is 07:32 AM.

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"