Search : in
By :

VBA code for a IF Function

Last answer on Jul 20, 2009 2:07:39 pm BST PM, on Jul 20, 2009 1:04:26 pm BST 
 Report this message to moderators

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

Configuration: Windows XP Internet Explorer 6.0
Excel 2003

Best answers for « VBA code for a IF Function » in :
[VBA] A function that returns the color of an active MFC Show[VBA] A function that returns the color of an active MFC This function returns the value of the active format in conditional formatting. With the function below, two values can be returned. Mode = 0: the value of Interior.ColorIndex...
Audio services missing ShowStereo Mixer/Audio Mixer missing Forcing the start of Windows Audio Service Installation of standard audio codecs If the audio mixer of Windows fails to launch, make sure that you have installed the drivers for sound card, downloaded...
Error Codes in Windows ShowError Codes in Windows The list below details the error codes displayed in the dialog boxes in Windows: Code Description _________________________________________________________________________ 1 Incorrect function....
Hyperlinks ShowIntroduction to anchors Hypertext links or hyperlinks (anchors) are HTML elements that, when clicked on, enable readers to visit a new address. Hyperlinked text is underlined by default. Hyperlinks are what connect web pages to one another. They...
Spreadsheets - Mathematical Functions ShowStandard Functions Function Description ABS() This function returns the absolute value of a number. It therefore returns the number, if it is positive, or the opposite (positive) if it is negative ODD(value) Rounds a number up to the...

1

Trowa, on Jul 20, 2009 1:23:50 pm BST

Hi PM

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

Reply to Trowa

2

PM, on Jul 20, 2009 1:34:07 pm BST

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.

Reply to PM

3

Trowa, on Jul 20, 2009 1:41:25 pm BST

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.

Reply to Trowa

4

 PM, on Jul 20, 2009 2:07:39 pm BST

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

Reply to PM