Hi,
I am working on a code that is supposed to get the values from columns that correspond to the last three rows of a table I created. It needs to be under this form because the numbers will be random.
I have a table in the first excel sheet with different values. I calculate how many rows and columns there are.
Then I get the last three values from the second sheet, belonging to the column Index. I will use these indexes in order to construct a code that will obtain these indexes and indentify the columns they correspond to in the first excel sheet. THen, I want it to extract these values for me.
The problem is it gets the three FIRST values not last
How can I fix this?
Option Explicit
Option Base 1
Sub ThreeBest()
Dim i As Integer, j As Integer, N As Integer
Dim Valeurs As Integer
Dim nb_Cells As Integer
Dim nb_Actions As Integer
nb_Cells = Worksheets("Actions").Cells(Rows.Count, 2).End(xlUp).Row - 1
nb_Actions = Worksheets("Actions").Cells(1, Columns.Count).End(xlToLeft).Column - 1
N = 3 'We want to choose the three last ones
ReDim ValeursAction(nb_Cells) As Variant
For i = 1 To N 'The source of my problem is in the following lines
Valeurs = Worksheets("Performance").Cells(nb_Actions + 7 - (i - 1), 9).Value '
'I place the value from the column corresponding to Valeurs in Performance
For j = 1 To nb_Cells
ValeursAction(j) = Worksheets("Actions").Cells(j + 1, Valeurs + 1)
With Sheets("Performance")
.Cells(5 + j, 5 - i) = ValeursAction(j)
End With
Next j
Next i
End Sub
Bookmarks