![]() |
VBA Permanent Code
Does anyone know how reference a cell in VBA and be able to use that
reference in another method? For example: sub test1() date = sheets("today").range("D2") end sub sub test2() msgbox = "today's date is " & date end sub Can not seem to be able to set Date Permanently so that I can use the reference in any method I want. Once it goes to the second sub, date is dropped and now empty. Thank you for helping me out. I appreciate any help I can get. Kevin Yang |
VBA Permanent Code
Declare it as public under declarations. Note that i've used da because you
can't use date as a variable it's a reserved word Public da Sub test1() da = Sheets("monday").Range("a1") Call test2 End Sub Sub test2() MsgBox ("today's date is " & da) End Sub " wrote: Does anyone know how reference a cell in VBA and be able to use that reference in another method? For example: sub test1() date = sheets("today").range("D2") end sub sub test2() msgbox = "today's date is " & date end sub Can not seem to be able to set Date Permanently so that I can use the reference in any method I want. Once it goes to the second sub, date is dropped and now empty. Thank you for helping me out. I appreciate any help I can get. Kevin Yang |
VBA Permanent Code
you could also pass it as a parameter (but I would read up on parameter
passing - particularly ByRef and ByVal): sub test1() Dim lngDate as long lngDate = sheets("today").range("D2") Call test2(lngdate) end sub sub test2(ByVal x as long) msgbox = "today's date is " & x end sub " wrote: Does anyone know how reference a cell in VBA and be able to use that reference in another method? For example: sub test1() date = sheets("today").range("D2") end sub sub test2() msgbox = "today's date is " & date end sub Can not seem to be able to set Date Permanently so that I can use the reference in any method I want. Once it goes to the second sub, date is dropped and now empty. Thank you for helping me out. I appreciate any help I can get. Kevin Yang |
All times are GMT +1. The time now is 05:50 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com