Hi Friends,
I need a little help in my code which is working in different logic. If I explain my scenario, I have an excel with two worksheets Sheet1(Form), Sheet2(Collation). I have a data in Sheet1 and kept a drop down list in column B (B2:B250) with Yes/No option. In column A there is a unique reference number of the data. What I need is.. whenever I select "Yes" in column B i.e. if I select "No" then it should be exit sub, but if I select "Yes"in B5, it should copy A5 and paste in A1 cell in "Collation" Sheet. irrespectively if I select "Yes" in B7, A7 should be copied to collation sheet A1.
I have used worksheet change event but every time I need to close and reopen the file after running the macro. Even if I delete the "Yes/No" in form sheet, the macro stop working while again selecting "Yes".
My current Code (in Sheet1)
In Module
I will be fine if only one code can be made. Also want to keep undo option working
I need a little help in my code which is working in different logic. If I explain my scenario, I have an excel with two worksheets Sheet1(Form), Sheet2(Collation). I have a data in Sheet1 and kept a drop down list in column B (B2:B250) with Yes/No option. In column A there is a unique reference number of the data. What I need is.. whenever I select "Yes" in column B i.e. if I select "No" then it should be exit sub, but if I select "Yes"in B5, it should copy A5 and paste in A1 cell in "Collation" Sheet. irrespectively if I select "Yes" in B7, A7 should be copied to collation sheet A1.
I have used worksheet change event but every time I need to close and reopen the file after running the macro. Even if I delete the "Yes/No" in form sheet, the macro stop working while again selecting "Yes".
My current Code (in Sheet1)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn, xOffsetColumn1 As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("B:B"), Target)
xOffsetColumn = -1
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Call Copycelldata
Else
Exit Sub
End If
Next
Application.EnableEvents = True
End If
End Sub
In Module
Code:
Sub Copycelldata ()
ActiveCell.Select
ActiveCell.Offset(0, -1).Select
Selection.Copy
Sheet2.Select
Range("A1").Select
ActiveSheet.Paste
End Sub
I will be fine if only one code can be made. Also want to keep undo option working
Last edited: