My excel file has 3 different type of VBA functions. In a sheet, I want to show the value from the defined name function. Initially I used this code to convert formula into string:
Function EvaluateString(strTextString As String)
Application.Volatile
EvaluateString = Evaluate(strTextString)
End Function
This function was placed in a individual module. The problem with this is that it runs in every module causing the running time for my other modules to be extremely slow.
I tried placing this function in a module itself, but it does not work. It gave me an error of "Only comments may appear after End Sub, End Function, or End Property".
This is my code when I received that prompt
Sub PasteAsText()
Dim lastRow As Long
lastRow = Worksheets("Data_Column").Cells(Rows.Count, 1).End(xlUp).Row
Function EvaluateString(strTextString As String)
Application.Volatile
EvaluateString = Evaluate(strTextString)
End Function
Worksheets("Data_Column").Range("D1:D" & lastRow).Clear
Worksheets("Data_Column").Range("C1:C" & lastRow).Copy
Worksheets("Data_Column").Range("D1:D" & lastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets("Data_Column").Range("D1:D" & lastRow).NumberFormat = "@"
Worksheets("Data_Column").Select
End Sub
EvaluateString? I would only expect it to slow things down if it was being used in thousands of cells. Also, why have you tried placing it within the code of a sub? That doesn't make sense, and as you found out won't allow the code to compile.