When I tryt to use this on a different worksheet, it doesn't work. The only difference is that the data starts are A3. Now, however, it's populating way to many cells with data, as if A:J is not being referenced at all. Here's what I changed the code to:
Public LastRow As Integer 'used as a constant once its value is known
Public myvalue As Variant 'passed between routines, so need global declaration
Sub DetermineEndRow() 'this works out the longest column from columns A to K, so runs just at start
Dim temp As Long
temp = 1
Range("A3").Select
For n = 1 To 11
currentRow = ActiveCell.Row
temp = Selection.End(xlDown).Row
If temp < 3000 Then 'I assume the list is less than 3000 rows long
LastRow = temp
Else: temp = currentRow
End If
ActiveCell.Offset(LastRow - currentRow, 3).Select
Next n
End Sub
Sub test()
DetermineEndRow 'to find the last row of data
For a = 1 To 11 'this is the loop to cycle through the columns
Cells(3, a).Select
myvalue = ActiveCell.Value
checkForError
temp = LastRow 'initialise value
While b < temp 'main loop to cycle through rows
Ignore = False
If myvalue < 0 Then
factor = 1
ElseIf myvalue > 0 Then
factor = -1
Else: Ignore = True 'where it is blank or N/A
End If
If Ignore = False Then 'we need to do something
currRow = ActiveCell.Row
For n = 1 To 5
Range("PnLStDev").Item(currRow + n, a).Value = Range("LogChanges").Item(currRow + n, a).Value * factor
temp = temp - 1 'reduce the rows to loop by the ones that are skipped
Next n
ActiveCell.Offset(n - 1, 0).Select
End If
ActiveCell.Offset(1, 0).Select
myvalue = ActiveCell.Value
checkForError
b = b + 1
Wend
b = 1 'reset b as the placeholder
Next a
End Sub
Sub checkForError()
If IsError(myvalue) Then myvalue = 0
End Sub
Bookmarks