Catlover22
New Member
- Joined
- Apr 27, 2016
- Messages
- 5
I just started learning the ropes to VBA and don't fully understand it yet. I am trying to create something that will change the value of two different cells, based on the contents of one cell.
Specifically, if the text in column B says "shoecare", then the contents in column E need to change to "48" and the contents in column F need to change to "16"
Then I need to repeat this for a couple other scenarios exactly like this except with different contents. I need for the entire column to be checked.
What I have so far:
-The first part is supposed to be IF B3 says shoecare, then change E3 and F3.
-The second part (to my understanding) is supposed to say essentially "repeat this down the entire column"
I get a "Block If without End If" error message
-Also, if I need to repeat this for multiple different instances, can I just copy this code and replace what variables I need in the correct spots?
Sub Shoecare()
If Range("B3").Value = "Shoecare" Then
Range("E3").Value = "48" And Range("F3").Value = "16"
Dim LastRow As Long
Dim i As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Range("B" & i).Value = "Shoecare" Then
Range("E" & i).Value = "48" And Range("F" & i).Value = "16"
End If
Next i
End Sub
Specifically, if the text in column B says "shoecare", then the contents in column E need to change to "48" and the contents in column F need to change to "16"
Then I need to repeat this for a couple other scenarios exactly like this except with different contents. I need for the entire column to be checked.
What I have so far:
-The first part is supposed to be IF B3 says shoecare, then change E3 and F3.
-The second part (to my understanding) is supposed to say essentially "repeat this down the entire column"
I get a "Block If without End If" error message
-Also, if I need to repeat this for multiple different instances, can I just copy this code and replace what variables I need in the correct spots?
Sub Shoecare()
If Range("B3").Value = "Shoecare" Then
Range("E3").Value = "48" And Range("F3").Value = "16"
Dim LastRow As Long
Dim i As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Range("B" & i).Value = "Shoecare" Then
Range("E" & i).Value = "48" And Range("F" & i).Value = "16"
End If
Next i
End Sub