Goto statement

D

Doc60

I trying to use the following but I am obviously missing something help would
be appreciated.

When lookinga this please remember I am trying to get the code to look at
the value in a specific cell (5,7) (or a bookmark) to evaluate if it is null
or has any value or number. This is a very simplistic way of what I am trying
to do but it will help if someone could advise me how to get this right.

Dim Number As Integer
Number = cell(5, 7) ' Initialize variable.
' Evaluate Number and branch to appropriate label.
If Number =null Then GoTo Line1 Else GoTo Line2
'If ActiveDocument.Tables(1).cell(5, 7).Range > 1 Then GoTo Line2 Else
GoTo
Line1

Line1:
Selection.MoveDown Unit:=wdLine, Count:=5
Line2:
Selection.MoveDown Unit:=wdLine, Count:=1

Thank you
 
D

David Sisson

To expound on the code Helmut gave you in another post.

Sub Macro2()
Dim oTbl As Table
Dim sTmp As String
Set oTbl = ActiveDocument.Tables(1)
With oTbl
sTmp = .Cell(5, 7).Range.Text
sTmp = Left(sTmp, Len(sTmp) - 2)
If IsNumeric(sTmp) Then
If sTmp > 1 Then
Selection.MoveDown Unit:=wdLine, Count:=1
End If
Else
Selection.MoveDown Unit:=wdLine, Count:=5
End If
End With
End Sub
 
D

Doc60

I have tried the suggested code however it doesn't seem to do what it should.
Can someone give me further assistance.

Thank you
 
D

David Sisson

I have tried the suggested code however it doesn't seem to do what it should.

Well, since you haven't shared with us the goal of what you're trying
to accomplish, we can only offer a best-guess solution.

If Cell(5,7) is empty, do what?
if Cell(5,7) is a number, do what?
 
H

Helmut Weber

Hi Doc60,
Dim Number As Integer
Number = cell(5, 7) ' Initialize variable.

you are trying to assign something
that isn't defined at all
to a number of type integer.

Have a look at this one,
which on purpose doesn't hide all complexity.

There is a lot of studying still to be done.

Sub Macro4()
Dim lTmp As Long ' a temporary long
With ActiveDocument.Tables(1)
lTmp = CLng(Left(.Cell(5, 2).Range.Text, _
Len(.Cell(5, 2).Range.Text) - 2))
End With
MsgBox lTmp
End Sub


Which will rise errors if not numeric, of course.


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
D

Doc60

Ok let me see if I can explain this better so that someone can help me.

I presently have code in a macro that is doing many calculation down several
columns and rows in a table that is already setup. However if in this
particular cell (5,7) if the person hasn't entered a number and has left it
blank I want the macro to skip that particular row which is the 5 in (5,7)
when the macro comes to that row each time it calculates down a column. If
there is a value in (5,7) then I want it to continue with the macro and
calculate the row when it comes time for that row 5 each time the macro goes
down a column and comes to row 5.

I hope this will help you help me.
 
G

George Lee

One problem is that if Line1 is implemented, Line2 is also implemented. I
don't know if that's intended although there are better and clearer ways to
do this. Goto statements shouldn't be used much and in this case they do seem
unnecessary. How about:

If Cell(5, 7) = Null Then
Selection.MoveDown Unit:=wdLine, Count:=5
Else
Selection.MoveDown Unit:=wdLine, Count:=1
End If
 
D

Doc60

With what was mentioned about the If Cell(5,7)=Null then statement do I have
to declare it as a variable? If so how would I do that and have the macro
recognize what is in Cell(5,7). The reason I ask is because I have tried what
was mentioned and kept getting debug errors.

Thanks
 

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

Top