VBA code for a IF Function

Closed
PM - Jul 20, 2009 at 08:04 AM
 Mukesh - May 26, 2011 at 06:29 AM
Hello,

I need help on the following:

Selecting a range on data e.g A1:A14
Searching for a certain value e.g 3000
if query is true then copy a value on the same row and paste to another cell e.g: 3000 is located in cell A5, copy values in D5 and paste into F5. (All the copying and pasting must happen on the same row as the value)

If query is false then put the value 0 in F5

i need this query to work with several different values e.g 3021, 3041...

Can anyone help with this?

Thanks

PMI
Related:

4 responses

I cant get the If function to do what I want. Everytime I put a range into the code, it comes up with a error. If I work with a single cell then the below works.

If Range("B2") = 3401 Then "ERROR ON THIS LINE WHEN I PUT A RANGE IN B2:B23"
Range("C2").Select
Selection.Copy
Range("D2").Select
ActiveSheet.Paste
Range("D2").Select
EndIf
1
after IF and Before EndIf
i.e. where you are typing your macro give space, I mean tab
If Range("B2") = 3401 Then
Range("C2").Select
Selection.Copy
Range("D2").Select
ActiveSheet.Paste
Range("D2").Select
EndIf

this is working I checked myself
0
Hi PM

Why do you want to use a vba code, when the IF function works perfectly???
0
Hi

i need to add it as part of a macro that already exists. I just cant get it to work, thats why im asking.
0
Record a macro and input the function.
Then look at the code using VBA.

If your macro doesn't work, copy-paste it into your next reply.
0