Using the If ElseIf Else Statement in Excel VBA (Macro)

preview_player
Показать описание
Grab the Free VBA Quick Reference Guide
The If Then statement in Excel VBA will execute some code if a specific criteria it met (Or is True). If the criteria is not met the ElseIf criteria is checked and if it is true it will execute the code and the Else will execute if all the criteria above are false (It is a catch-all).

Code:
=================
Sub IfThenElseIfElse()

mbox = MsgBox("Have you Subscribed to EverydayVBA's Youtube Channel", vbYesNoCancel, "Quick Question")

If mbox = vbYes Then
MsgBox "You Are awesome!"
ElseIf mbox = vbNo Then
MsgBox "Why Not"
Else
MsgBox "What Just happened"
End If

End Sub
Рекомендации по теме
Комментарии
Автор

When I transpose data for purchases per month and year, there are missing months or years when a purchase did not happen.
for example i may have column headers as 2013_1, 2013_2, 2014_4 (2013_3 needs to be inserted and headers labeled) can I email you a header that I need a script written that inserts missing months or years.???

stamatarsenikos
Автор

Excellent
I need a vba
IF condition is met then copy and paste value to another sheet or workbook automatically
OR
IF condition is met then take screen shot and save it to any defined destination automatically

gamputerskills
Автор

I've add a snapshot from a file. So end of Mei I want to Copy the data from range "U5:U106",   End of June I want to copy range "V5:V102" etc, etc, and copy this into antoher workbook. The problem is how can I pre-define the range based on a cell in the file?  E.g.: Reporting Month:  "mei-18" in cell "AA5" then the macro will select range "U5:U102" and copy. Or with a Msgbox. etc. Who can help?

mout
Автор

New post.
I have 2 columns, 3 and 6.
Row begins on 4.
I want to be able to have curser in next empty cell working across horizontal.
Example.
If c4 has data then f4 should have curser, also if both c4 and f4 have data then curser should go to c7 and if that has data then curser goes to f7 and so on down the page. Below is my code that works for column 3 now. How do I make this work for both columns?
I have tried all I know but no luck..

Dim lrow as long

If sheet1.range("C4") = "" then

Lrow=cells(rows.count, 3).end(xlup).offset(1, 0) .select
Else
Lrow=cells(rows.count, 3).end(xlup).offset(3, 0).select
End

QQ-nbic
Автор

Wow! I got tuned out within the first 28 seconds. So let me give you some constructive critique.

1) Eye Contact Please! You can't be shy and have a YouTube video that shows you.

2) You could have typed this whole thing up and saved us time watching you type.

3) Stick to the topic, or make another video about your preferred options.

4) You mentioned that you used Tabs to make the code readable, but you started your code within the Sub-End Sub flush! Do as I say not as I do???

ms-excelat-sfpl
Автор

how to programme in excel vba
IF b true then
List =a

Elseif c true then
List = a

Elseif d true then
List = a

Elseif b and c true then
List = a
Elseif b and d true then
List = a
Elseif c and d true then
List = a
Elseif a and c and d true then
List = a

Elseif a and b and d true then
List = a
Elseif a and c and d true then
List = a
Elseif a and e and d true then
List = a
Elseif e and c and d true then
List = a
Loop c=" b="e="

karthikdinthakurthi