Raymondc190466
New Member
- Joined
- Aug 19, 2016
- Messages
- 24
- Office Version
- 365
- Platform
- Windows
I've got an excel code (different userforms), that was created by one of my colleagues.
So I have a little background of what the codes do.
This code creates an error message (compile error: expected array), and I can't figure out what is wrong.
This line of code causing the error:
Look_up_Data = Look_up_data_range.Value
ReDim Look_up_Data(End_line)
So I have a little background of what the codes do.
This code creates an error message (compile error: expected array), and I can't figure out what is wrong.
This line of code causing the error:
Look_up_Data = Look_up_data_range.Value
ReDim Look_up_Data(End_line)
Code:
Private Sub CommandButton1_Click()
Const Look_up_sheet = "Shelf_Life_900"
Const CST_First_Line = 2
Const CST_Item_Col = 1
Const CST_Shelf_Life_Col = 2
Const CST_Number_of_Periods = 3
Const CST_Technical_Responsible_Col = 4
Const CST_Date_Col = 5
Const CST_Remarks_Col = 6
Dim ctl_Cont As Control
Dim Row As Long
Dim ws As Worksheet
Dim MyString As String
Dim Item As Variant
Dim Look_up_data_range As Range
Dim Look_up_Data As String
Dim End_line As Integer
Dim Item_Name As String
Dim Item_exist As Boolean
Dim Index_Cell As Integer
Dim My_Cell As Variant
Dim x As Range
'Check if TxtBox_Item is not empty
If TxtBox_Item_Number.Text = "" Then
MsgBox ("Item is not filled in")
Exit Sub
End If
'Activate look up worksheet
Worksheets(Look_up_sheet).Activate
ActiveSheet.Unprotect
ActiveSheet.AutoFilterMode = False
'Read look data
Set x = Sheets("Request_for_Shelf_Life").Range("A:A").Find(TxtBox_Item_Number.Text)
If Not x Is Nothing Then TxtBox_TC.Text = x.Offset(, 2).Value
Set Look_up_data_range = ActiveSheet.UsedRange
End_line = Look_up_data_range.Rows.Count
Set Look_up_data_range = ActiveSheet.Range( _
ActiveSheet.Cells(CST_First_Line, CST_Item_Col), _
ActiveSheet.Cells(End_line, CST_Item_Col))
Look_up_Data = Look_up_data_range.Value
ReDim Look_up_Data(End_line)
Index_Cell = 0
For Each My_Cell In Look_up_data_range.Cells
Look_up_Data(Index_Cell) = My_Cell.Value
Index_Cell = Index_Cell + 1
Next My_Cell
'Check If data already present
Item_Name = TxtBox_Item_Number.Text
Item_exist = False
For Each Item In Look_up_Data
If Item = Item_Name Then
Item_exist = True
Exit For
End If
Next Item