TheRedCardinal
Active Member
- Joined
- Jul 11, 2019
- Messages
- 250
- Office Version
- 365
- 2021
- Platform
- Windows
Hi all,
I have a table that consists of varying columns, and rows. Its exact format varies with each run, but it will have 2 columns at the end of the table, called "Adjusted Value" and Comments. The number of rows varies.
There are lines in the workbook beyond the bottom of the table that are not part of the data.
I tried to write a sub that does the following:
I designed this code (only meant for finding the highest 5 values):
So as I'm here, it obviously isn't working quite right!
When I ran the macro, I got values 1 and 2 fine but it turns out there are about 11 different lines that have value 3 in them, and they were ALL populated with the text string.
Further, items 4 and 5 did not then get posted, because I suspect that the sheet classes the 4th highest discrete value as actually being the 14th highest value.
So my questions are:
I was thinking of sorting the column by Adjusted Value and using top 5 rows but that gives me the same issue as (1) above.
Thanks in advance!
I have a table that consists of varying columns, and rows. Its exact format varies with each run, but it will have 2 columns at the end of the table, called "Adjusted Value" and Comments. The number of rows varies.
There are lines in the workbook beyond the bottom of the table that are not part of the data.
I tried to write a sub that does the following:
- Finds the 5 highest values in the Adjusted Value Tab
- Picks other lines randomly from the table until the % of values "selected" exceeds 20% of the total value in that column
- In the cell next to the value, enter the text "This row has been selected for checking"
I designed this code (only meant for finding the highest 5 values):
Code:
Sub RandomChecks()
Dim CheckText As String
Dim ValueRange As Range, ValueColumn As Range
Set WS1 = Sheets("2. Final Data")
With WS1
Set ValueColumn = .Range("A1:Z1").Find("Adjusted Value")
CheckText = "This line has been selected for checking"
LRow = Range("A1").End(xlDown).Row
Set ValueRange = WS1.Range(Cells(2, ValueColumn.Column), Cells(LRow, ValueColumn.Column))
If LRow > 5 Then
Counter = 5
Else
Counter = LRow
End If
For MyTemp = 1 To Counter
For Each CellA In ValueRange
If CellA.Value = Application.WorksheetFunction.Large(ValueRange, MyTemp) Then
CellA.Offset(0, 1).Value = CheckText
End If
Next CellA
Next MyTemp
End With
End Sub
So as I'm here, it obviously isn't working quite right!
When I ran the macro, I got values 1 and 2 fine but it turns out there are about 11 different lines that have value 3 in them, and they were ALL populated with the text string.
Further, items 4 and 5 did not then get posted, because I suspect that the sheet classes the 4th highest discrete value as actually being the 14th highest value.
So my questions are:
- Is it possible to code this so that once a value is found, it is ignore in the next loop
- How do I get the random selection element of this to work, including an instruction that if it has been selected in the top 5 process, it should be excluded
- Any comments on how to code this better?
I was thinking of sorting the column by Adjusted Value and using top 5 rows but that gives me the same issue as (1) above.
Thanks in advance!