how to add 2 conditions in a if statement

bulletshiva

New Member
Joined
Jun 6, 2018
Messages
11
Hello,

I have a code which will check the range for letter "E" and will copy all rows to sheet purchasing.

Now i have a need that the macro should check another condition before the rows are copied to sheet 'purchasing'

It should check for "E" or "F" in column 'type'. If of "F" my below macro should work with this condition.

can somebody modify the code to do the job


Private Sub Purchase()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet

' Change worksheet designations as needed
Set Source = ActiveWorkbook.Worksheets("Process_Data")
Set Target = ActiveWorkbook.Worksheets("Purchasing")

j = 1 ' Start copying to row 1 in target sheet
For Each c In Source.Range("E2:S500") ' Do 1000 rows
If c = "E" Then
'Source.Rows(c.Row).Copy Target.Rows(j)
Source.Range(Cells(c.Row, 1), Cells(c.Row, 3)).Copy Target.rows(j)
j = j + 1
End If
Next c
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
If you simply want to change it to check for "E" or "F", simply change this line:
Code:
[COLOR=#333333]If c = "E" Then[/COLOR]
to this:
Code:
[COLOR=#333333]If (c = "E") or [/COLOR][COLOR=#333333](c = "F") [/COLOR][COLOR=#333333]Then[/COLOR]
 
Upvote 0
Ok, but it is not "or" function. It should be "and" function. More over the type "E" or "F" is not the range mentioned in the macro. This is mentioned under column "type"
 
Upvote 0
I thought I understood what you were asking. If not, then your description is very unclear to me as to what your data looks like and what you are after.

I think you would be well served to post a data example along with your expected results. A lot of times, a picture explains a lot more than words.

You cannot upload files to this site. But there are tools you can use to post screen images. They are listed in Section B of this link here: http://www.mrexcel.com/forum/board-a...forum-use.html.
Also, there is a Test Here forum on this board that you can use to test out these tools to make sure they are working correctly before using them in your question.
 
Upvote 0

Forum statistics

Threads
1,214,665
Messages
6,120,803
Members
448,990
Latest member
rohitsomani

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