Please explain code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Could someone please explain to me what the code below is doing. It is part
of a macro to insert rows, but each time I run the macro its going to Endsub.



On Error GoTo EndSub
Application.EnableCancelKey = xlDisabled
ActiveSheet.Select
Let Back = activecell.Column * (-1) + 3
Selection.Offset(0, Back).Range("A1").Select
Let test = activecell
If test = 1 Then GoTo Continue
If test = 0 Then GoTo EndSub
GoTo EndSub
 
Karen,
Comment out the 'OnError..." statement so you can see which line is causing
the error.

NickHK
 
Weird code. I steped through the code without any errors. Had to add labels
to get it to compile.

Have you steped through the code. Highlight the row that starts with
Application and press F9. the line should go yellow. Then Press F8 to step
through the code.

The code is really doing nothing except changing the selected cell.


Sub weird()



On Error GoTo endsub
Application.EnableCancelKey = xlDisabled
ActiveSheet.Select

'take active cell column multiply by -1 and adds 3
Let Back = ActiveCell.Column * (-1) + 3

'changes the column of the selected cell
'this is weird!
'Not sure if it is refereing cell A1 or the selected cell
Selection.Offset(0, Back).Range("A1").Select

'Tests the value of the active cell
Let test = ActiveCell
If test = 1 Then GoTo continue
If test = 0 Then GoTo endsub
GoTo endsub


continue:
endsub:
End Sub
 
The code always takes the active cell back to column C. There are two
conditions that takes the code to EndSub. One is when there's an error and
the other is when the variable "test" (which is column C in the current row)
is blank or equal to 0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top