View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default IF-THEN to skip portion of macro

Do not branch - it is heresy :-))

If Range("Deleted_Today") = 0 Then
SkipMove
Else
' ... do the rest
End If

You could also put teh rest in a separate sub, and call that on the Else
condition, thereby having a flow control master sub.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"excelnut1954" wrote in message
ups.com...
I"ve been designing spreadsheets for about 20 yrs, but just started VBA
this last summer. I used to write macros in the older versions of Lotus
(pre graphic interface). The problem I have now was easy to overcome
back then.

I'm sure I'm not structuring my code efficiently, but things are
working ok for now. I'll have to go back later when I learn more, and
re-do what I'm writing now, to make it more efficient. That's part of
the process for me.

I have a file where we add new lines (records), and delete lines, each
day. We move the lines to be deleted to another folder within this
file. We sort the new list by one of the columns, format all the cells
to look nice and pretty.Then we print the new list.

What I have now is a giant macro initiated by a button the user clicks
after entering in the new records at the bottom of the list, and making
an entry in a column for each line to be moved.

I'll outline how the macro flows:
*Move records to be deleted
*Sort the list, and format cells.
*Print report.

I am sure I should want these sections seperated. But, as I've learned
VBA on the run, I just entered coding in this giant macro.

What I have done so far today is to start another sub at the bottom of
this giant macro, and I named it
Private Sub SkipMove()

I have a cell that counts the number of lines that are shown to be
moved. I have named that cell "Deleted_Today".

My question is: Can I use an IF-THEN statement, right when the user
clicks the button, that will look at the value of "Deleted_Today", and
if it's 0, then move on to the the sub SkipMove ?

In the old days of Lotus macros, I used to use a Branch statement to do
such things. Is the way I described above, creating another sub, the
correct way of "branching" the instructions?
If so, can somone help me with a way to write the IF-THEN code?
Something like this, in English:
IF "Deleted_Today" = 0, then go to SkipMove, else continue the macro.

Thanks to all who take the time to respond. This is a great forum, and
I've learn alot reading the questions/answers from others.

excelnut