using end if inside an if loop

smakatura

Board Regular
Joined
May 27, 2011
Messages
141
my code looks like this so far


legend for coding/question below
  • newvariable is the variable name for an inputted value
  • ...A actions -the commands if the value is A
  • ...X actions - commands if the value is not A or B

HTML:
if newvariable = "A" then
     ....A Actions
else 
     .....X Actions
End if
I want to add a B value. if the value is B, I want it to do nothing - end the loop and move on with the macro...so something like

HTML:
if newvariable = "A" then
    ....A Actions
else if newvariable = "B" then
    endif
else 
    .....X Actions
End if
I think the first endif is probaby the wrong way to do it.

Essentally I can have 6 values- A, B, and X (where is X anything but A or B) . If A, do the A actions. If B, I want to exit the loop. If anything but A or B do the X actions.

what is the proper coding?
 
Last edited:

smakatura

Board Regular
Joined
May 27, 2011
Messages
141
will "exit for" work within the if-endif statement?

I am not sure if something like "resume next" would be the right action.
 

MAP1168

New Member
Joined
Aug 29, 2011
Messages
11
You could try something like this.
Not sure how many X actions you have. But the loop ends when newvariable="B"
note "the value of # is the number you have given to your subroutine"

Sub Main#()

do until newvariable ="B"
if newvariable="A"
then
..."A" actions
else
...."X" actions
endif
Loop

endsub
 

smakatura

Board Regular
Joined
May 27, 2011
Messages
141
bc I could not find the right wording for ending the loop with in the if statemetn, I went with the code below, it worked great


HTML:
if newvalue <> "B" then   
  if newvariable = "A" then
     ....A Actions
  else 
     .....X Actions
  End if
End if
 

Forum statistics

Threads
1,082,048
Messages
5,362,890
Members
400,696
Latest member
Kclynn

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top