Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Adding a row with the previous one if....

Good morning,

I would like to add all cells in a row with the cells of the previous
row, if the cell in column A = the value of the cell in the previous
row in column A...up until Row 5 included

In other words, let's say that A13= Mary, A14= Mary, A15 =Mary, then I
would like that B14=B15+B14, C14=C15+C14, etc until column BK, then
delete row 15.etc...

Then, B13=B14+B13, C13=C14+C13 , etc....and hen delete row 14.

Here's the code so far, but it works only for Column B ...

Sub Test()

Application.EnableEvents = False
Application.ScreenUpdating = False


Dim DerLig As Long, DerCol As Integer
Dim Rg As Range, i As Long, a As Long


With ActiveSheet
DerLig = .Cells.Find(What:="*", _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
DerCol = .Cells.Find(What:="*", _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
Set Rg = .Range("A5", .Cells(DerLig, DerCol))
End With
With Rg
.Sort Key1:=.Item(1, 1), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End With
For i = Rg.Rows.Count To 1 Step -1
If Rg(i, 1) = Rg(i - 1, 1) And i = 5 Then
a = a + 1
Else
If a 0 Then
Rg(i-1, 2).Value = (Rg(i, 2)+Rg(i,2))
Rg(i + 1, 1).Resize(a).EntireRow.Delete
a = 0
Else
If a < 1 Then a = 1
Rg(i-1, 2).Value = (Rg(i, 2)+Rg(i,2))
a = 0
End If
End If
Next
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
'---------------------------------------

This code was nicely provided me by Denis

Thanks for your time

Denys
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Adding a row with the previous one if....

Found....

thanks to Denis....again

Denys
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 one to the number from the previous cell with text... T.[_2_] Excel Discussion (Misc queries) 8 October 14th 09 03:03 AM
Adding calculated value to previous cell electricbluelady Excel Discussion (Misc queries) 3 June 26th 08 08:06 PM
adding 1 to previous cell value using code Jock Excel Programming 2 October 8th 07 05:21 PM
building YTD figures by adding to a previous months total axialtilt Excel Discussion (Misc queries) 7 July 24th 06 04:07 PM
Adding values from previous worksheets firecord Excel Worksheet Functions 1 June 27th 05 09:59 AM


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