In sheet Job Request cell A2 I select a company form a list. In the same sheet cell B2,…
- User
In sheet Job Request cell A2 I select a company form a list. In the same sheet cell B2, I select an Issue Type from a list. In cell C2, I select a Location from a list. In cell D2, I manually enter Details of Request.
What I would like is to write a VBA code that is triggered by chnage of value in cell B2. If the value in B2 is 'Service Request' then it will search Sheet 'Start Page' T5:T64 for all values that match the value of I2 in Sheet 'Job Request', then for each corresponding match in 'Start Page' column T, it will copy the values of the same row in column U as text only into Sheet 'Job Request' cell D2. Where multiple matches are found each row must be represented in a different line.
- Assistant
Here's a code that should achieve what you're looking for:
Private Sub Worksheet_Change(ByVal Target As Range) 'check if the changed cell is B2 and its value is "Service Request" If Target.Address = "2" And Target.Value = "Service Request" Then 'get the value of I2 in Job Request sheet Dim searchString As String searchString = Sheets("Job Request").Range("I2").Value
code - User
In the following VBA code, is there a conflict for 2 . . . Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Address = "2" And Target.Value = "Service Request" Then
Call ServiceType
If Not Intersect(Target, Range("C2:E2")) Is Nothing Then Exit Sub
If Not Intersect(Target, Range("F2")) Is Nothing Then 'Currently in F2
Call Complete
Exit Sub
End If
If Not Intersect(Target, Range("A2")) Is Nothing Then 'Currently in A2
If Application.CountA(Range("B2:E2")) = 0 Then Range("G2:I2").Calculate Range("F3:H3").Calculate
Call Checks
Else: Call Incomplete
End If End If End Sub
- Assistant
There is no conflict with the 2 reference in the code you provided.
The code is using the Worksheet_Change event to trigger various subroutines based on the value of Target, which is a range object representing the cells that were changed. The first line of the code checks if more than one cell was changed and exits the sub if so.
The next line checks if the value in cell B2 is "Service Request" and calls the ServiceType subroutine if it is.
The following lines check if the changed cell is within ranges C2:E2 or F2 and exits the sub if so. If the changed cell is in cell F2, it calls the Complete subroutine.
The last part of the code checks if the changed cell is in cell A2. If so, it checks if there are any non-blank cells in the range B2:E2. If all cells in that range are blank, it calculates certain ranges and calls the Checks subroutine. If there are non-blank cells in that range, it calls the Incomplete subroutine.
- User
I might be missing an End If in the code. If Iam where is the best place to put it
- Assistant
It's possible that there is a missing
End Ifin the code you provided, since eachIfstatement should have a correspondingEnd If. To check if there is a missingEnd If, you can count the number ofIfstatements in the code and compare it to the number ofEnd Ifstatements.If there is indeed a missing
End If, you should place it at the end of the code block where it belongs. For example, if the missingEnd Ifbelongs to theIf Not Intersect(Target, Range("A2")) Is Nothing Thenstatement, then you should place it after theEnd Iffor theElse: Call Incompletestatement.Here's an example of how the code should look with the missing
End Ifadded:code