Macro Loop Not Working Correctly - Using XLUP

ubergeek

New Member
Joined
Dec 6, 2005
Messages
15
Hello,

I need some help with a macro loop written in Excel 2007. The macro starts at the bottom of a list of data. Rows have been inserted into the data to build in total lines; these lines are notated as "New". The loop works it's way up through the data, adding in the data for totals for each "New" row.

The problem occurs with the two formulas to add sums to the total lines. I've tried my best to write the code to sum whatever is above the total line up until the next blank cell. (The next blank cell is the next total row.)

For some reason the formula appears to be using the same number of rows for each line as was in the first line it was ran on. For example, if the first total line only has 1 row of data, the formula only sums one line for the rest of the total lines.

Now for the strange part, if I just pick another total line and step through the macro on that line, it works correctly.

Any suggestions please?

Thank you in advance!!!

The Wonky Loop Code:

'Make Totals
Do While Not IsEmpty(ActiveCell)
If (ActiveCell) = "New" Then
ActiveCell.Offset(0, -11).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 2).Select
With ActiveCell
.Formula = "=SUM(" & .Offset(0, 0).End(xlUp).Address(0, 0) _
& ":" & .Offset(-1, 0).Address(0, 0) & ")"
End With


ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
With ActiveCell
.Formula = "=SUM(" & .Offset(0, 0).End(xlUp).Address(0, 0) _
& ":" & .Offset(-1, 0).Address(0, 0) & ")"
End With
ActiveCell.Offset(0, 1).Select
End If


ActiveCell.Offset(-1, 0).Select
Loop
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I think there's probably an alternative way to code this, but can you post an example of your spreadsheet - be easier to understand what you are trying to achieve and the layout etc
 
Upvote 0
Below is sample data; I apologize for the messy format! I couldn't figure out a way to get anything better looking up!!


Payee Member Name Member ID Name More Info Package Avg EOM Count Avg Count Effective Rate Payment Amount


Brand A 01GH Name 1 Info 1 1 2.0 555.0 $0.2000 $10.35 Ignore
Brand A 01GH Name 1 Info 1 2 286.0 555.0 $0.2000 $60.62 Ignore
Brand A 01GH Name 1 Info 1 3 16.0 555.0 $0.2000 $12.83 Ignore
Brand A 01GH Name 1 Info 1 4 3.0 555.0 $0.2000 $10.53 Ignore
New
Brand B 25AD Name 2 Info 1 1 312.5 338.0 $0.1770 $65.31 Insert
Brand B 25AD Name 2 Info 1 1 25.5 338.0 $0.1770 $14.51 Ignore
New
Brand C 42AK Name 3 Info 1 4 65.5 71.0 $0.9000 $21.59 Insert
New
Brand D 89MDD Name 4 Info 1 3 31.0 98.0 $0.8000 $15.49 Insert
Brand D 89MDD Name 4 Info 1 2 360.5 98.0 $0.8000 $73.81 Ignore
Brand D 89MDD Name 4 Info 1 2 56.0 98.0 $0.8000 $19.91 Ignore
Brand D 89MDD Name 4 Info 1 5 6.0 98.0 $0.8000 $11.06 Ignore
New
Brand E 58 Name 5 Info 1 5 2.0 52.0 $0.1770 $10.35 Insert
Brand E 58 Name 5 Info 1 3 332.5 52.0 $0.1770 $68.85 Ignore
New
Brand F 1218 Name 6 Info 1 4 29.5 31.0 $0.6000 $15.22 Insert
New
Brand G 99990 Name 7 Info 1 1 10.0 1,100.0 $0.1110 $11.77 Insert
Brand G 99990 Name 7 Info 1 4 3.0 1,100.0 $0.1110 $10.53 Ignore
Brand G 99990 Name 7 Info 1 3 2.0 1,100.0 $0.1110 $10.35 Ignore
Brand G 99990 Name 7 Info 1 3 1,795.5 1,100.0 $0.1110 $327.80 Ignore
Brand G 99990 Name 7 Info 1 2 2.0 1,100.0 $0.1110 $10.35 Ignore
Brand G 99990 Name 7 Info 1 2 3.0 1,100.0 $0.1110 $10.53 Ignore
New
Brand H HBN555 Name 8 Info 1 5 61.0 11.0 $0.2100 $20.80 Insert
New
Brand I PCQ1 Name 9 Info 1 1 1.0 988.0 $0.0500 $10.18 Insert
New
Brand J TG2299 Name 10 Info 1 2 1.0 363.0 $0.0111 $10.18 Insert
Brand J TG2300 Name 10 Info 1 3 353.0 363.0 $0.0111 $72.48 Ignore
New
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top