looping through each row

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,215,201
Messages
6,123,617
Members
449,109
Latest member
Sebas8956

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