Do...Loop???

boxboy30

Board Regular
Joined
Sep 16, 2011
Messages
84
How do I loop the following formula. If A2=A1 then sum(C2+C1)...keep that going until it is false. I've written the following code but I have to keep writing an IF statement in order for it to keep comparing the A column.

Sub Macro_test()
If [a2].Text = [a1].Text Then
[c1].Value = [b2].Value + [b3].Value
If
[a3].Text = [a1].Text Then
[c1].Value = [
b3].Value + [b2].Value + [b1].Value

Else: End If
Else: End If

End Sub

how do I keep it going without manually writing it?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
It's a For Next Loop:

It will start the loop at a value of 2 and with each iteration (Next) it will execute the code in the loop until the value of LR+1 is reached.

A more simple example

Code:
For i=2 to 7
Msgbox i
Next i
 
Upvote 0
okay...next question for the day...

ActiveWorkbook.Worksheets("activeworkbook").Sort.SortFields.Clear

I want this code to work on any spreadsheet I have open...do I really have to have the name of the spreadsheet? Can't I just have it work on the activeworkbook? If so, what am i missing?
 
Upvote 0
you could change the "activeworkbook" to 1 or 2 or 3...etc...


I don't understand so the code would read

ActiveWorkbook.Worksheets(1).Sort.SortFields.Add Key:= _
Range("D1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
 
Upvote 0
Yeah! that worked...now how do I set a filter to delete certain information regardless how long it is....

example:

Selection.AutoFilter
ActiveSheet.Range("$F$1:$F$109585").AutoFilter Field:=1, Criteria1:= _
"Get Into It"
Range("4141:40478").Select
ActiveWindow.SmallScroll Down:=-234
Selection.Delete Shift:=xlUp
Selection.AutoFilter

the problem with this one is that if the spreadsheet is different than the one I'm working on it will delete all rows 4141:40478 and that might not contain the information I need it to delete. I want it to delete what was filter only, regardless of the which cells there are...can i do that?
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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