I have an xla with a bunch of functions. Basically each of these functions perform a vertical lookup on another worksheet. Here's a basic example of one of them:
Function ax2Project_Address(projectnumber)
If (projectnumber = "?") Then
ax2Project_Address = "Unknown address"
Else
ax2Project_Address = Application.VLookup(projectnumber, Sheets("AX Data").Range("A:K"), 11, False)
End Function
This allows users to simply call the function with the project number on the worksheet and it gives them the address, without having to write the vertical lookup themselves.
What I want to do now is have the row of the current cell to autofit its height to its content. The problem is that this obviously should be done after the cell has been filled with the adress, but since the function ends after the return, the autofit command won't be executed.
Is there a way to execute the autofit command in a function after the return?
Or is there a completely different approach I could use?
Worksheet_calculate
event and it'll run each time the sheet has been recalculated.Application.Evaluate
but I couldn't get it to work withAutofit
. I think theWorksheet_calculate
event is your best bet.