Need Help creating an IF THEN scenario
Solved/Closed
blakerwilson
Posts
4
Registration date
Friday April 28, 2017
Status
Member
Last seen
May 3, 2017
-
May 1, 2017 at 12:03 PM
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 - May 10, 2017 at 08:28 PM
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 - May 10, 2017 at 08:28 PM
Related:
- Need Help creating an IF THEN scenario
- Create an instagram account - Guide
- How to create an icon file - Guide
- How to create an onlyfans - Guide
- Create an outlook account - Guide
- How to create an a5 document in word - Guide
4 responses
The if statement syntax is as follows:
=IF(logic_test,true,false)
So, with that in mind and considering Cell A1="hi".
If we have in cell B1:
=if(A1="hi","the word hi is there","some other word is there")
...would produce "the word hi is there" in cell B1
SO, use that as an example, and have a go. You can nest if then statments, as in:
=IF(logic_test#1,if(LogicTest#2if#1IsTrue,"TRUE FOR BOTH","true for one not for two"),"false for one")
I hope this helps.
Have a go!
=IF(logic_test,true,false)
So, with that in mind and considering Cell A1="hi".
If we have in cell B1:
=if(A1="hi","the word hi is there","some other word is there")
...would produce "the word hi is there" in cell B1
SO, use that as an example, and have a go. You can nest if then statments, as in:
=IF(logic_test#1,if(LogicTest#2if#1IsTrue,"TRUE FOR BOTH","true for one not for two"),"false for one")
I hope this helps.
Have a go!
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
May 3, 2017 at 04:19 AM
May 3, 2017 at 04:19 AM
Hello Blake,
You could try a macro code for this also. Assign the following code to a button and see if it does the task for you. The code is untested so test it in a copy of your work book first.
On clicking on the button, the code filters Column A on sheet 1 for the criteria "X" (as per your sample) and will then transfer the relevant rows of data (from Column B to Column E) to sheet 2.
I hope that this helps.
Cheerio,
vcoolio.
You could try a macro code for this also. Assign the following code to a button and see if it does the task for you. The code is untested so test it in a copy of your work book first.
Sub TransferData() Dim lr As Long Application.ScreenUpdating = False Sheet1.Range("A1", Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp)).AutoFilter 1, "X", 7 lr = Sheet1.Range("B" & Rows.Count).End(xlUp).Row If lr > 1 Then Sheet1.Range("B2", Sheet1.Range("E" & Sheet1.Rows.Count).End(xlUp)).Copy Sheet2.Range("A" & Rows.Count).End(3)(2).PasteSpecial xlValues Sheet2.Columns.AutoFit End If Sheet1.[A1].AutoFilter Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
On clicking on the button, the code filters Column A on sheet 1 for the criteria "X" (as per your sample) and will then transfer the relevant rows of data (from Column B to Column E) to sheet 2.
I hope that this helps.
Cheerio,
vcoolio.
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
May 3, 2017 at 06:07 AM
May 3, 2017 at 06:07 AM
Greetings again Blake,
Another method that you may find simpler is a Worksheet_Change event (no buttons required). The code is as follows:-
With this code, each time that you place an "X" in Column A and then click away (or press enter or down arrow), the relevant row of data will be transferred to Sheet 2. The "X" must be your last entry per row.
To implement this code:-
- Right click on the Sheet1 tab.
- From the menu that appears, select "view code".
- In the big white field that then appears, paste the above code.
Return to Sheet1 (your input sheet) and test it. But, again, remember to test the code in a copy of your work book first.
Just another option.
Cheerio,
vcoolio.
Another method that you may find simpler is a Worksheet_Change event (no buttons required). The code is as follows:-
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Target.Value = vbNullString Then Exit Sub If Intersect(Target, Columns("A:A")) Is Nothing Then Exit Sub Application.ScreenUpdating = False If Target.Value = "X" Then Target.EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2) End If Sheet2.Columns.AutoFit Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
With this code, each time that you place an "X" in Column A and then click away (or press enter or down arrow), the relevant row of data will be transferred to Sheet 2. The "X" must be your last entry per row.
To implement this code:-
- Right click on the Sheet1 tab.
- From the menu that appears, select "view code".
- In the big white field that then appears, paste the above code.
Return to Sheet1 (your input sheet) and test it. But, again, remember to test the code in a copy of your work book first.
Just another option.
Cheerio,
vcoolio.
blakerwilson
Posts
4
Registration date
Friday April 28, 2017
Status
Member
Last seen
May 3, 2017
May 3, 2017 at 10:29 AM
May 3, 2017 at 10:29 AM
that might be easier... I am guessing I could replace X with YES or something that would mean something to others using this sheet?
Thanks for your help. The first solution seems to work and I will try the second because I like that idea of eliminating the button.
Thanks for your help. The first solution seems to work and I will try the second because I like that idea of eliminating the button.
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
>
blakerwilson
Posts
4
Registration date
Friday April 28, 2017
Status
Member
Last seen
May 3, 2017
May 4, 2017 at 03:06 AM
May 4, 2017 at 03:06 AM
No worries Blake. Glad that I was able to help.
Yes, you can replace the "X" with any criteria that you like. Just change it in the codes above.
Cheerio,
vcoolio.
Yes, you can replace the "X" with any criteria that you like. Just change it in the codes above.
Cheerio,
vcoolio.
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
>
Blocked Profile
May 5, 2017 at 10:01 PM
May 5, 2017 at 10:01 PM
G'day Mark,
I'm glad that you approve! Hopefully, Blake is no longer in a pickle.
Cheerio,
vcoolio.
I'm glad that you approve! Hopefully, Blake is no longer in a pickle.
Cheerio,
vcoolio.
I just heard back from the group I am working with and they would like me to modify this code a bit. Instead of a YES, they would like to copy that row to another sheet if there is anything in that cell...
If Target.Value = "YES" Then
Target.EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
End If
is that doable? and if so, what do I need to put in the code to make this work?
Great job on this by the way!
If Target.Value = "YES" Then
Target.EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
End If
is that doable? and if so, what do I need to put in the code to make this work?
Great job on this by the way!
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
May 10, 2017 at 08:28 PM
May 10, 2017 at 08:28 PM
Hello Blake,
Change this line :-
to
This will allow you to place any value in Column A. Make sure that everyone is aware that the criteria needs to be the last entry in any row.
Cheerio,
vcoolio.
Change this line :-
If Target.Value = "YES" Then
to
If Target.Value <> "" Then
This will allow you to place any value in Column A. Make sure that everyone is aware that the criteria needs to be the last entry in any row.
Cheerio,
vcoolio.
May 2, 2017 at 01:11 PM
May 2, 2017 at 04:42 PM
Have fun!
May 2, 2017 at 05:15 PM
https://drive.google.com/file/d/0B8ZUqlS0WQfUV21PVVpyR2hJQWc/view?usp=sharing