ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   subroutine variable decleration issue (https://www.excelbanter.com/excel-programming/366010-subroutine-variable-decleration-issue.html)

Christmas May[_2_]

subroutine variable decleration issue
 
The following works:

sub subroutine(optional Byval strVariable as string = "Default String")

Can I do something similar to the following, which doesn't work?

sub subroutine2(optional byval rngVariable as range = range("A1:B2"))

Also are these routines public or private?

Thanks in advance,

Christmas May

Norman Jones

subroutine variable decleration issue
 
Hi Chritmas,

Try:

Sub subroutine2(Optional rng As Range)

If rng Is Nothing Then Set rng = Range("A1:B2")


Also are these routines public or private?


That depends on the required scope.

Lokk in VBA help for 'Scope', 'Private' and 'Public'



---
Regards,
Norman



"Christmas May" wrote in message
...
The following works:

sub subroutine(optional Byval strVariable as string = "Default String")

Can I do something similar to the following, which doesn't work?

sub subroutine2(optional byval rngVariable as range = range("A1:B2"))

Also are these routines public or private?

Thanks in advance,

Christmas May





All times are GMT +1. The time now is 02:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com