Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Creating functions

Hi,

I have written the following code in a module: (essentially all it does is
find the next blank line for me to use)

Public Function SR()

Dim row, col As Integer

col = 4
row = 7

While Worksheets("Main").Cells(row, col).Value < ""
row = row + 1
Wend

End Function

Can someone please tell me:

- is this the right place to put it (it does seem to work)
- how I return the value back to my calling private sub (Button click)

Cheer

Steve

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating functions

Public Function SR()

Dim row, col As Integer

col = 4
row = 7

While Worksheets("Main").Cells(row, col).Value < ""
row = row + 1
Wend
sr = row
End Function

Public Sub Main()
Dim lastrow as Long
lastrow = Sr
msgbox LastRow
End sub

Depending on how your data is laid out, You might change SR to

Public Function Sr()
Dim rng as Range
set rng = Worksheets("Main").Cells(rows.count,4).End(xlup)(2 )
if rng.row < 7 then
set rng = Worksheets("Main").Range("D7")
end if
sr = rng.row
End Function

--
Regards,
Tom Ogilvy



"Steve" wrote in message
...
Hi,

I have written the following code in a module: (essentially all it does is
find the next blank line for me to use)

Public Function SR()

Dim row, col As Integer

col = 4
row = 7

While Worksheets("Main").Cells(row, col).Value < ""
row = row + 1
Wend

End Function

Can someone please tell me:

- is this the right place to put it (it does seem to work)
- how I return the value back to my calling private sub (Button click)

Cheer

Steve



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Creating functions

Spot on

Many thanks

"Tom Ogilvy" wrote:

Public Function SR()

Dim row, col As Integer

col = 4
row = 7

While Worksheets("Main").Cells(row, col).Value < ""
row = row + 1
Wend
sr = row
End Function

Public Sub Main()
Dim lastrow as Long
lastrow = Sr
msgbox LastRow
End sub

Depending on how your data is laid out, You might change SR to

Public Function Sr()
Dim rng as Range
set rng = Worksheets("Main").Cells(rows.count,4).End(xlup)(2 )
if rng.row < 7 then
set rng = Worksheets("Main").Range("D7")
end if
sr = rng.row
End Function

--
Regards,
Tom Ogilvy



"Steve" wrote in message
...
Hi,

I have written the following code in a module: (essentially all it does is
find the next blank line for me to use)

Public Function SR()

Dim row, col As Integer

col = 4
row = 7

While Worksheets("Main").Cells(row, col).Value < ""
row = row + 1
Wend

End Function

Can someone please tell me:

- is this the right place to put it (it does seem to work)
- how I return the value back to my calling private sub (Button click)

Cheer

Steve




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating functions grumpy Excel Worksheet Functions 4 July 14th 06 09:31 AM
Creating Functions -=Merovingian=- Excel Programming 4 October 30th 05 02:50 PM
creating new functions Peter R Knight Excel Worksheet Functions 3 September 19th 05 02:03 PM
Creating Help within functions Joe Carroll Excel Programming 1 June 5th 05 03:56 AM
Creating a functions Kimi Excel Worksheet Functions 1 April 8th 05 05:27 AM


All times are GMT +1. The time now is 01:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"