outarr = Range(.Cells(1, 4), .Cells(lastrow2, 5))
For kk = 3 To 4
outarr(i, kk - 1) = inarr(j, kk)
Next kk
Dim outarr(0 To 1, 3 To 44)
outarr(1, 3) = "test"
MsgBox outarr(1, 3)
Private Sub Test()
Dim Lastrow, i As Long
Dim Searchfor, Lookup, Result1, Result2 As Variant
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Searchfor = Cells(1, 62)
Lookup = Range(Cells(1, 1), Cells(Lastrow, 1))
Result1 = Range(Cells(1, 3), Cells(Lastrow, 3))
Result2 = Range(Cells(1, 8), Cells(Lastrow, 8))
For i = 1 To Lastrow
If Lookup(i, 1) = Searchfor Then
Cells(2, 62) = Result1(i, 1) & " " & Result2(i, 1)
Exit For
End If
Next i
End Sub
so for speed it is much faster to load them once and do all the lookups using the same call
Private Sub Fixer()
Dim RowCounter As Long
For RowCounter = 2 To GetLastRow(ActiveSheet, 1)
If Cells(RowCounter, 59) = True Then
Call ChangeTaskDates(Cells(RowCounter, 6), Cells(RowCounter, 1), Cells(RowCounter, 36), Cells(RowCounter, 37))
End If
Next RowCounter
End Sub
Public Function ChangeTaskDates(ByRef ProjectID As String, ByRef TaskID As String, ByRef StartDate As String, ByRef EndDate As String) As String
Dim BaseURL As String: BaseURL = "REDACTED"
Dim GUID As String: GUID = Worksheets("API").Range("B1")
Dim RawJSON As String: RawJSON = GetHTTP(BaseURL & GUID & "&projectid=" & ProjectID & "&taskid=" & TaskID & "&startdate=" & Left(StartDate, 10) & "&duedate=" & Left(EndDate, 10) & "&FORMAT=JSON")
Dim JSON As Object: Set JSON = JsonConverter.ParseJson(RawJSON)
Dim ErrorDesc As String: ErrorDesc = JSON("results")(1)("ERRORDESCRIPTION")
If JSON("status") = "fail" Then
Dim FixedDate As String: FixedDate = Format(SRegEx("(\d+\/\d+\/\d+)", ErrorDesc), "yyyy-mm-dd")
Call GetHTTP(BaseURL & GUID & "&projectid=" & ProjectID & "&taskid=" & TaskID & "&startdate=" & FixedDate & "&duedate=" & FixedDate & "&FORMAT=JSON")
End If
Set JSON = Nothing
End Function
Private Function GetHTTP(ByVal URL As String) As String
On Error Resume Next
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.Send
GetHTTP = .ResponseText
End With
End Function
Private Sub Fixer()
Dim RowCounter As Long
lrow = GetLastRow(ActiveSheet, 1)
inarr = Range(Cells(1, 59), Cells(lrow, 59))
For RowCounter = 2 To lrow
If inarr(RowCounter, 1) = True Then
Call ChangeTaskDates(Cells(RowCounter, 6), Cells(RowCounter, 1), Cells(RowCounter, 36), Cells(RowCounter, 37))
End If
Next RowCounter
End Sub
Sub Vlook_Up2()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
[C2].FormulaR1C1 = "=IF(VLOOKUP(RC2,Table1,1,1)=RC2,VLOOKUP(RC[-1],Table1,2,1),-999)"
LR2 = Sheets("Kweries").Range("B" & Rows.Count).End(xlUp).Row
Range("C2:C" & LR2).FillDown
Calculate
Range("C3:C" & LR2).Copy
Range("C3:C" & LR2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
You are still accessing the worksheet in a loop so you can make your code faster by loading the column 59 into an array. like this:
Private Sub Fixer()
Dim i As Long
Dim Lastrow As Long: Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Dim Run As Variant: Run = Range(Cells(1, 59), Cells(Lastrow, 59))
Dim ProjectID As Variant: ProjectID = Range(Cells(1, 6), Cells(Lastrow, 6))
Dim TaskID As Variant: TaskID = Range(Cells(1, 1), Cells(Lastrow, 1))
Dim StartDate As Variant: StartDate = Range(Cells(1, 36), Cells(Lastrow, 36))
Dim EndDate As Variant: EndDate = Range(Cells(1, 37), Cells(Lastrow, 37))
For i = 1 To Lastrow
If Run(i, 1) = True Then
Call ChangeTaskDates(ProjectID(i, 1), TaskID(i, 1), StartDate(i, 1), EndDate(i, 1))
End If
Next i
End Sub
Private Sub DateFixer_Click()
Dim RowCounter As Long
Dim lrow As Variant: lrow = GetLastRow(ActiveSheet, 1)
Dim inarr As Variant: inarr = Range(Cells(1, 59), Cells(lrow, 59))
For RowCounter = 2 To lrow
If inarr(RowCounter, 1) = True Then
If Cerberus.ChangeTaskDates(Cells(RowCounter, 6), Cells(RowCounter, 1), Cells(RowCounter, 36), Cells(RowCounter, 37)) = "ERROR" Then Cells(RowCounter, 60) = "ERROR"
End If
Next RowCounter
End Sub