Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2006, 07:56 AM
Authorized User
 
Join Date: Jan 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gws_byte
Default 'Application.ThisCell" equivelent for VBA 2000?

Hi Guys,

I'm trying to transfer some code i wrote on my 2003 XL to a machine running XL2K, everything works EXCEPT the Application.ThisCell part, does anyone have an idea how to do the same thing in 2K? (Code follows - Mileage is a cell with a True/False value)

Thanks

Function OdometerDiff(Mileage)
If Mileage Then
    If Application.ThisCell.Offset(-1, 0) = "" Then
    OdometerDiff = Application.ThisCell.Offset(0, -1) - Application.ThisCell.Offset(-2, -1)
    Else: OdometerDiff = Application.ThisCell.Offset(0, -1) - Application.ThisCell.Offset(-1, -1)
    End If
Else: OdometerDiff = ""
End If

End Function

Dave - MAD

nil illegitimi carborundum

Semper in excreta, sumus solum profundum variat
__________________
Dave - MAD
nil illegitimi carborundum
Semper in excreta, sumus solum profundum variat
 
Old January 31st, 2006, 08:12 AM
Authorized User
 
Join Date: Jan 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gws_byte
Default

OOPS!!

Re-thought the problem and used a formula instead

I would still be interested to hear if anyone knows the VBA answer though...

Thanks

Dave - MAD

nil illegitimi carborundum

Semper in excreta, sumus solum profundum variat
 
Old January 31st, 2006, 08:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Dave,

I think the ThisCell Property was only added to Excel at XL2003 so no backwards compatability I'm afraid.

I know this because historically it was nigh on impossible to replicate the same functionality. You can see why they restricted it because if your UDF tried to amend the value of the currently calculating cell (containing the UDF) then nasty things happen to Excel's calculation flow. Still it was mighty annoying for those of us that could be trusted not to crash Excel and wanted to do something useful.

The VBA answer to your problem would be a little tedious - you'd need to pass a reference to the cell next to the UDF cell as an additional argument to the function. You could then use this object to check for blank nieghbouring cells etc.

Maccas

 
Old January 31st, 2006, 09:17 AM
Authorized User
 
Join Date: Jan 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gws_byte
Default

Hey Maccas,

Thanks for the quick reply! I was afraid of something like that...

I achieved the same result with a nested 'If' function, makes me wonder how useful UDF's were in 2K in a scenario where you wanted to use predictable data patterns arrayed around a formula cell, where the formula cells adress was not fixed...? Oh well...


Dave - MAD

nil illegitimi carborundum

Semper in excreta, sumus solum profundum variat





Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2000 VBA code John Stark Excel VBA 0 March 1st, 2006 06:02 AM
VBA for Excel 2000...HELP! lhardesty Excel VBA 2 August 20th, 2004 09:08 AM
Help with VBA (MS Word 2000) vb_programmer Beginning VB 6 0 May 22nd, 2004 12:26 AM
Access 2000 VBA problem dubs70 Access VBA 2 February 18th, 2004 11:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.