Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using the And formula in a VBA macro

I'm learning VBA and have got stuck!

I have a spreadsheet with 7 columns of information. I want to work
down the spreadsheet, testing 4 criteria. The critera look at the
columns and test to see if they apply. I can use the And function to
return a true or false value.

I want to use VBA to say that if a particular condition applies then
put 'text1' in the cell to the right, if not test the next condition
and if that is true then put 'text2' in the cell to the right, if not
test the next condition.

I've recorded the macro and am using an activecell.formula = approach.
I just can't get it to run in an Else If way. The first test runs
but the second doesn't. I can't put an if statement before the
activecell.formula.

Has anyone got any ideas on how to overcome this?

Much appreciated


Corinne R
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using the And formula in a VBA macro

Dim cell as Range
for each cell in Range("A1:A200")
if cell.Value 100 then
cell.offset(0,1).Value = "'100"
elseif cell.Value 75 then
cell.offset(0,1).Value = "'75"
elseif cell.value 50 then
cell.offset(0,1).Value = "'50"
else
cell.offset(0,1).Value = "'<=50"
end if
Next

--
Regards,
Tom Ogilvy

"Corinne R" wrote in message
om...
I'm learning VBA and have got stuck!

I have a spreadsheet with 7 columns of information. I want to work
down the spreadsheet, testing 4 criteria. The critera look at the
columns and test to see if they apply. I can use the And function to
return a true or false value.

I want to use VBA to say that if a particular condition applies then
put 'text1' in the cell to the right, if not test the next condition
and if that is true then put 'text2' in the cell to the right, if not
test the next condition.

I've recorded the macro and am using an activecell.formula = approach.
I just can't get it to run in an Else If way. The first test runs
but the second doesn't. I can't put an if statement before the
activecell.formula.

Has anyone got any ideas on how to overcome this?

Much appreciated


Corinne R



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using the And formula in a VBA macro

Thank you Don

I have managed to get the program to behave in the way I want and
realised where I was going wrong. But there may be a better way to
achieve this and I'd love to learn. It's quite longwinded!

Here's my code:

Dim StudentStatus As String
ActiveCell.FormulaR1C1 = "=AND(RC[-4]=6,RC[-2]=""LW-118"",RC[-3]=21)"
If ActiveCell.Value = "True" Then
StudentStatus = "Prog + NCE"
ActiveCell.Value = StudentStatus
ElseIf ActiveCell.Value = "False" Then
ActiveCell.FormulaR1C1 = "=AND(RC[-4]3,RC[-4]<6,RC[-2]=""LW-118"")"
If ActiveCell.Value = "True" Then
StudentStatus = "Mop Up"
ActiveCell.Value = StudentStatus
ElseIf ActiveCell.Value = "False" Then
ActiveCell.FormulaR1C1 = "=AND(RC[-4]=6,RC[-3]<21,RC[-2]=""LW-118"")"
If ActiveCell.Value = "True" Then
StudentStatus = "Prog"
ActiveCell.Value = StudentStatus
ElseIf ActiveCell.Value = "False" Then
StudentStatus = "Incomplete"
ActiveCell.Value = StudentStatus
End If
End If
End If
End Sub




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 136
Default Using the And formula in a VBA macro

Paste the following formula into E1. If that is not where you
ultimately want it, copy it to the cell you want.
=IF(AND(A1=6,B1=21,C1="LW-118"),"Prog+NCE",IF(AND(A13,A1<6,C1="LW-118"),"Mop
Up",IF(AND(A1=6,B1<21,C1="LW-118"),"Prog","Incomplete")))

Corinne Ross wrote:

Thank you Don

I have managed to get the program to behave in the way I want and
realised where I was going wrong. But there may be a better way to
achieve this and I'd love to learn. It's quite longwinded!

Here's my code:

Dim StudentStatus As String
ActiveCell.FormulaR1C1 = "=AND(RC[-4]=6,RC[-2]=""LW-118"",RC[-3]=21)"
If ActiveCell.Value = "True" Then
StudentStatus = "Prog + NCE"
ActiveCell.Value = StudentStatus
ElseIf ActiveCell.Value = "False" Then
ActiveCell.FormulaR1C1 = "=AND(RC[-4]3,RC[-4]<6,RC[-2]=""LW-118"")"
If ActiveCell.Value = "True" Then
StudentStatus = "Mop Up"
ActiveCell.Value = StudentStatus
ElseIf ActiveCell.Value = "False" Then
ActiveCell.FormulaR1C1 = "=AND(RC[-4]=6,RC[-3]<21,RC[-2]=""LW-118"")"
If ActiveCell.Value = "True" Then
StudentStatus = "Prog"
ActiveCell.Value = StudentStatus
ElseIf ActiveCell.Value = "False" Then
StudentStatus = "Incomplete"
ActiveCell.Value = StudentStatus
End If
End If
End If
End Sub




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with the macro or with the formula Igneshwara reddy[_2_] Excel Worksheet Functions 6 March 22nd 07 09:16 PM
Macro or Formula? A.S. Excel Discussion (Misc queries) 1 September 20th 06 05:26 PM
Help with macro or formula JAZZNAURA Excel Discussion (Misc queries) 0 August 18th 06 08:41 AM
Macro/Formula Help? fluci Excel Discussion (Misc queries) 8 August 5th 05 11:31 PM
Formula to macro...anyone?? adidas VBA Excel Programming 12 December 4th 03 04:41 AM


All times are GMT +1. The time now is 10:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"