Thread: Excel Question
View Single Post
  #10  
Old 08-25-2005, 10:01 AM
Link774 Link774 is offline
Junior Member
 
Join Date: Sep 2004
Posts: 22
Default Re: Excel Question

I think the code you posted would just select the last entry when the macro is executed. You need a function, not a subroutine. This should do the trick (grr, the board screwed up my formatting):

Function LastConsecutiveNonBlankValue(range)
lastEntry = ""
For Each entry In range
If entry.Value = "" Then
LastConsecutiveNonBlankValue = lastEntry
Exit For
End If
lastEntry = entry.Value
Next
If LastConsecutiveNonBlankValue = "" Then
LastConsecutiveNonBlankValue = lastEntry
End If
End Function

This is just a custom excel function, you'd probably want to place it in the workbook in which it is needed by pressing Alt+F11 to open the VB editor, then selecting the excel file you're working on from the list on the left, then going to Insert->Module. Double click the new module to open it, then paste that code in. Alt+F11 will get you back to your sheet, where you can use this function as you would any excel function. Let me know if you have any problems!

--Link
Reply With Quote