VBA code with multiple condition

ryan8200

Active Member
Joined
Aug 21, 2011
Messages
357
There are 5 candidates with 4 favorites sports. WD denotes weekday,while WE represent weekend. If the candidate takes part in a sports, the status will be "Y" and "N" if the participants did not take part in the sports.

The tasks here is to write VBA code to extract data with status "Y" on weekday (WD) and status"N" on weekend (WE).

Kindly refer to the URL below for the sample data and expected outcome.

https://ibb.co/R4YyYgj.

Your kind assistance to the question I posted will be greatly appreciated.


 
Ok this does it:

Code:
With Sheets("Sheet1")
    fr = 8
    lr = .Range("A" & .Rows.Count).End(xlUp).Row
    If lr > fr - 2 Then
        .Range("A" & fr & ":B" & lr).ClearContents
        .Range("A" & fr) = "Hobbies"
        .Range("B" & fr) = "Candidates"
    End If
    For j = 2 To 11
        For i = 3 To fr - 2
            If (.Cells(i, j) = "Y" And .Cells(2, j) = "WD") Or (.Cells(i, j) = "N" And .Cells(2, j) = "WE") Then
                .Cells(fr + 1, 1) = .Cells(i, 1)
                .Cells(fr + 1, 2) = .Cells(1, j).MergeArea(1)
                fr = fr + 1
            End If
        Next
    Next
End With

Change sheet name to suit your sheet.

Did your data start A1 ? I try to hit F5 and a message appeared and asked for the macro name. Is this normal ?
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Yes you put the Sub Macro1() at the top then the code then end it with End Sub
 
Upvote 0
That's a surprise as for me its provided exactly the same result as your example.
 
Upvote 0

Forum statistics

Threads
1,216,191
Messages
6,129,429
Members
449,509
Latest member
ajbooisen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top