greywolfnsl
New Member
- Joined
- Jun 3, 2016
- Messages
- 6
So I am very new to excel and I have been trying to search a range for a word and return a 1 or zero. Then I need it to loop through the list that will vary in size. I have I keep getting errors. I have been at this for many hours banging my head at it.
Here is where the stuff is at:
The "Calendar" Sheet has the text in range B4:N34
The "Work Sheet Grocery List" Column A has the text I am trying to match it to
The "Work Sheet Grocery List" Column B is where I am trying to return the 1 or 0 if column A text is in the Calendar range
So if the Calendar has Pudding in cell D8, I want the other sheet to put a 1 in column B of the corresponding A column. Also "Pudding will be in Column A numerous times.
Here is what I have so far: (I have tried strings and arrays)
Sub GroceryListPart1()
' Get the last row with text
Dim LastRow As Long
'this get the last row EVEN IF there is a break in the center. Starts at the bottom and works it way up
LastRow = Worksheets("Grocery List").Cells(Rows.Count, 1).End(xlUp).Row
Debug.Print LastRow
'Dim Calendar As Range
'Set Calendar = Worksheets("calendar").Range("A1:A8")
Dim calendarrange As String
Dim Calendarsheet As String
Dim calendar(0 To 27)
calendarrange = "B4:N34"
Calendarsheet = "Calendar"
Set calendar = Worksheets(Calendarsheet).Range(calendarrange)
Dim i As Long, Total As Long
' Use LastRow in loop
For i = 2 To LastRow
If InStr(calendar, Worksheets("Grocery List").Cells(i, 1)) Then
Worksheets("Grocery List").Cells(i, 2) = 1
Else
Worksheets("Grocery List").Cells(i, 2) = 0
End If
Next i
End Sub
Thank you for any help!
Here is where the stuff is at:
The "Calendar" Sheet has the text in range B4:N34
The "Work Sheet Grocery List" Column A has the text I am trying to match it to
The "Work Sheet Grocery List" Column B is where I am trying to return the 1 or 0 if column A text is in the Calendar range
So if the Calendar has Pudding in cell D8, I want the other sheet to put a 1 in column B of the corresponding A column. Also "Pudding will be in Column A numerous times.
Here is what I have so far: (I have tried strings and arrays)
Sub GroceryListPart1()
' Get the last row with text
Dim LastRow As Long
'this get the last row EVEN IF there is a break in the center. Starts at the bottom and works it way up
LastRow = Worksheets("Grocery List").Cells(Rows.Count, 1).End(xlUp).Row
Debug.Print LastRow
'Dim Calendar As Range
'Set Calendar = Worksheets("calendar").Range("A1:A8")
Dim calendarrange As String
Dim Calendarsheet As String
Dim calendar(0 To 27)
calendarrange = "B4:N34"
Calendarsheet = "Calendar"
Set calendar = Worksheets(Calendarsheet).Range(calendarrange)
Dim i As Long, Total As Long
' Use LastRow in loop
For i = 2 To LastRow
If InStr(calendar, Worksheets("Grocery List").Cells(i, 1)) Then
Worksheets("Grocery List").Cells(i, 2) = 1
Else
Worksheets("Grocery List").Cells(i, 2) = 0
End If
Next i
End Sub
Thank you for any help!