How to convert sub procedure to function

V

Varun

Hi,

I need to convert the sub procedure that extracts some values and puts them
in an array (named logical_layer2) into a function. How can I go about doing
this?

Any help is appreciated. Thanks.


Sub extract_tech_file()

Dim startrow1, currow1, h As Integer
Dim n As Integer, p As Integer
Dim logical_layer2() As Variant
ReDim logical_layer2(1 To 100)

Worksheets("Temp3").Cells.Find(What:="$$define_physical_layer",
After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlDown, MatchCase:=False, SearchFormat:=False).Activate

startrow1 = ActiveCell.Row

'add initial array here

n = 1
logical_layer2(n) = Worksheets("Temp3").Cells(startrow1, 3)
n = n + 1

Do While startrow1 <> currow1
Cells.FindNext(After:=ActiveCell).Activate
currow1 = ActiveCell.Row
If currow1 <> startrow1 Then
logical_layer2(n) = Worksheets("Temp3").Cells(currow1, 3)
n = n + 1
End If
Loop
 
J

Jim Skrydlak

The most important difference between a sub and a function is that a function
returns a value. In this case, you can make the function return TRUE (if it
worked properly) or FALSE (if it didn't).

Something along the lines of

Function extract_tech_file(arguments here) as Boolean

extract_tech_file=TRUE

insert logic here. set extract_tech_file to FALSE if there's an error.

End Function


Good luck.

Jim
 

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