I am trying to assign the value of a worksheet cell to a constant variable in a VBA macro. The logic behind that action is that the end user is supposed to enter the current
From help: You can't use variables, user-defined functions, or intrinsic Visual Basic functions (such as Chr) in expressions assigned to constants.
In your case you have to use a variable.
No it is not possible. As the word suggest it should be Constant.
Workaround:
Public Const weekRange As String = "$B$1"
Then in your code:
Sub Something()
Dim thisWeek As Integer: thisWeek = Range(weekRange).Value
'~~> some codes here
End Sub
I know this is old but I was looking to do this myself and came up with this. I use a function:
Function insertPNA(strSource As Long) As String
Dim strResult As String
strResult = Replace(strSource, strSource, ThisWorkbook.Sheets("Audits & Actuals").Range("pnacode").Value)
insertPNA = strResult
End Function
Whenever I want the pna code I just type insertpna(1). Hope someone finds this useful. (It doesn't have to be "1" obvs, I just used it to minimize typing.)