looping through each row

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I tried to write a code to loop through each row, but it only outputs for the last row.

VBA Code:
Sub vba_loop_range()
Dim c As Range, LRow As Long

LRow = Application.Max(7, Range("A" & Rows.Count).End(xlUp).Row)

For Each c In Range("A" & LRow)
    If c.Offset(0, 10) = "" Then
'        Range("M" & ActiveCell.Row) = StockQuote(c.Value)
        Range("M" & ActiveCell.Row) = LastOptionPrice(Range("A" & ActiveCell.Row) & Format(Range("E" & ActiveCell.Row), "yymmdd") & Left(Split(Range("C" & ActiveCell.Row), "-")(1), 1) & Format(Range("d" & ActiveCell.Row) * 1000, "00000000"))
        Range("O" & ActiveCell.Row) = WorksheetFunction.Sum(Replace(Range("G" & ActiveCell.Row), "*", "") * Range("M" & ActiveCell.Row) * 100 - Range("I" & ActiveCell.Row))
        Range("Q" & ActiveCell.Row) = WorksheetFunction.Sum(Range("O" & ActiveCell.Row) - Range("J" & ActiveCell.Row))
        Range("R" & ActiveCell.Row) = Range("Q" & ActiveCell.Row) / Range("J" & ActiveCell.Row)
    End If
Next c
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
There is only a single c in Range("A" & LRow) so your "loop" is nonexistent.
You would have a better chance of getting some help if you provide more information on exactly what you want to accomplish and the layout of your data.
 
Upvote 0

Forum statistics

Threads
1,216,025
Messages
6,128,341
Members
449,443
Latest member
Chrissy_M

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