RockandGrohl
Well-known Member
- Joined
- Aug 1, 2018
- Messages
- 788
- Office Version
- 2010
- Platform
- Windows
Hi guys,
Not sure if there exists a much faster way, or even whether using case statements would work faster, but in a list I am trying to go down cell by cell and insert a value based on criteria, as below:
Trouble is it takes a few minutes to do 1,000 rows and I can have 90,000 rows to evaluate one by one.
I suppose I can filter to where AH is not blank and then apply the value to each line.
If I look at a For Each within an autofilter, I'm a bit stuck on the Enquiry bit, how do I find the largest number of enquiries, then match it to a header it corresponds to, within this loop?
What I'm trying to perform VBA wise is essentially this:
Cheers!
Not sure if there exists a much faster way, or even whether using case statements would work faster, but in a list I am trying to go down cell by cell and insert a value based on criteria, as below:
VBA Code:
Range("AG2").Activate
Do Until Cells(ActiveCell.Row, "A").Value = ""
If Cells(ActiveCell.Row, "AH").Value <> "" Then
' is Exclusive
ActiveCell.Value = "EXC-" & ActiveCell.Offset(0, 1).Value
End If
If Cells(ActiveCell.Row, "AH").Value = "" And Cells(ActiveCell.Row, "AI").Value <> "" Then
' is Multi
ActiveCell.Value = "MUL-" & ActiveCell.Offset(0, 2).Value
End If
If Cells(ActiveCell.Row, "AH").Value = "" And Cells(ActiveCell.Row, "AI").Value = "" Then
' is Enquiry
ActiveCell.FormulaR1C1 = "=INDEX(R1C42:R1C47,MATCH(MAX(RC42:RC47),RC42:RC47,0))"
cat = ActiveCell.Value
ActiveCell.Value = "ENQ-" & Mid(cat, 5)
End If
ActiveCell.Offset(1, 0).Activate
Loop
Trouble is it takes a few minutes to do 1,000 rows and I can have 90,000 rows to evaluate one by one.
I suppose I can filter to where AH is not blank and then apply the value to each line.
If I look at a For Each within an autofilter, I'm a bit stuck on the Enquiry bit, how do I find the largest number of enquiries, then match it to a header it corresponds to, within this loop?
VBA Code:
' Add in customer type
Dim cl As Range
Dim rng As Range
Set rng = Range("AG2:AG" & LastrowDF)
' Exclusive
Range("A1:BC" & LastrowDF).AutoFilter Field:=34, Criteria1:="<>"
For Each cl In rng.SpecialCells(xlCellTypeVisible)
With cl
.Value = "EXC-" & cl.Offset(0, 1).Value
End With
Next cl
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
' Multi
Range("A1:BC" & LastrowDF).AutoFilter Field:=34, Criteria1:=""
Range("A1:BC" & LastrowDF).AutoFilter Field:=35, Criteria1:="<>"
For Each cl In rng.SpecialCells(xlCellTypeVisible)
With cl
.Value = "MUL-" & cl.Offset(0, 2).Value
End With
Next cl
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
' Enquiry
Range("A1:BC" & LastrowDF).AutoFilter Field:=34, Criteria1:=""
Range("A1:BC" & LastrowDF).AutoFilter Field:=35, Criteria1:=""
For Each cl In rng.SpecialCells(xlCellTypeVisible)
With cl
'Application.WorksheetFunction.Index(Sheets("Workers List").Range("C3:C13"), Application.WorksheetFunction.Match(1, Sheets("Workers List").Range("D3:D13"), 0), 1)
.Value = "ENQ-" & WorksheetFunction.Index(Range("AP1:AU1"), WorksheetFunction.Match(WorksheetFunction.Max(Range("AP" & ActiveCell.Row & ":AU" & ActiveCell.Row), Range("AP" & ActiveCell.Row & ":AU" & ActiveCell.Row), 0)))
End With
Next cl
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
What I'm trying to perform VBA wise is essentially this:
VBA Code:
"=INDEX(R1C42:R1C47,MATCH(MAX(RC42:RC47),RC42:RC47,0))"
Cheers!