Catyclaire85
New Member
- Joined
- Nov 23, 2021
- Messages
- 20
- Office Version
- 2016
- Platform
- Windows
Hi, hope you can point out my error.
The code I have attached is to find a row of data and update it. When I step through it the code works to identify the row and what should go there but when it finishes running the row found is left blank. What have I done/missed please?
The code I have attached is to find a row of data and update it. When I step through it the code works to identify the row and what should go there but when it finishes running the row found is left blank. What have I done/missed please?
VBA Code:
Sub IAUpdates()
Dim Output(1 To 10000, 1 To 28) As Variant
Dim ArraytoLookup As Variant
Dim ValtoLookup As Variant
Dim Rowfound As Integer
Dim OutCol As Integer ‘start column for Shifts table sheet1
Dim Details As Variant
Details = Sheet1.Range(“A1:AB28”)
ArraytoLookup = Sheet2.Range(“A1:A10000”)
ValtoLookup = Sheet1.Range(“C5”) ‘IA Title to locate in Sheet 2 to update
Rowfound = IsInArrayNumbers(ArraytoLookup, ValtoLookup)
If Rowfound > 0 Then
Output(Rowfound, 2) = Sheet1.Range(“K4”)
Output(Rowfound, 3) = Sheet1.Range(“C7”)
Output(Rowfound, 4) = Sheet3.Range(“A11”)
Output(Rowfound, 5) = Sheet1.Range(“E7”)
Output(Rowfound, 6) = Sheet1.Range(“C9”)
Output(Rowfound, 7) = Sheet1.Range(“E9”)
Output(Rowfound, 8) = Sheet1.Range(“C11”)
Output(Rowfound, 10) = Sheet1.Range(“F11”)
If Sheet1.Range(“F11”) = “Completed” Then
Output(Rowfound, 9) = Sheet3.Range(“A13”)
End If
Output(Rowfound, 11) = Sheet1.Range(“H9”)
Output(Rowfound, 12) = Sheet1.Range(“B14”)
If Sheet1.OptionButton1 = True Then
Output(Rowfound, 13) = “Impact”
Else
If Sheet1.OptionButton2 = True Then
Output(Rowfound, 13) = “Benefit”
End If
End If
Output(Rowfound, 14) = Sheet1.Range(“X17”)
Output(Rowfound, 24) = Sheet1.Range(“Z6”)
Output(Rowfound, 25) = Sheet1.Range(“Z8”)
Output(Rowfound, 26) = Sheet1.Range(“Z10”)
Output(Rowfound, 27) = Sheet1.Range(“Z12”)
Output(Rowfound, 28) = Sheet1.Range(“Z14”)
End If
Sheet2.Range(“A” & Rowfound & “:AB” & Rowfound) = Output
End Sub
Function IsInArrayNumbers(arr As Variant, valueToFind) As Variant
‘ searches for a number within a provided array
‘ best for searches in one dimensional arrays
IsInArrayNumbers = 1
IsInArrayNumbers = Application.Match(valueToFind, arr, 0)
If IsError(IsInArrayNumbers) Then IsInArrayNumbers = -1
End Function