Formulas not filling in without F2+enter

  • Thread starter Thread starter Zachary Harrison
  • Start date Start date
Z

Zachary Harrison

Hi all-

I am using vba code to setup a few blph() functions in a workbook. If
you are not familiar with bloomberg or this function, please read on as
my problem is more general!

After my code has finished running the formulas don't execute unless I
goto the cell and hit F2 then enter. Pressing F9 for calculate does
not do the trick.

I tried recording this action of F2+enter but the macro just shows
selecting the cell and setting the formula to what I already had it at.

Is there a way to simulate this F2+enter in vba code? Any other ideas?

Thank you,

Zach
 
Try something like

Dim Rng As Range
For Each Rng In Selection.SpecialCells(xlCellTypeFormulas)
If Rng.HasArray = True Then
Rng.FormulaArray = Rng.Formula
Else
Rng.Formula = Rng.Formula
End If
Next Rng



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Did you select your range and run Chip's code?

Another option.
Select your range (all the whole worksheet) and

edit|replace
what: = (equal sign)
with: = (equal sign)
replace all
 
Force recalculation with two instructions :

Worksheets("XXX").EnableCalculation = False
Worksheets("XXX").EnableCalculation = True

GL
 
Hi Zach,
I've not run across what Dominique posted before, so unless you
have done that yourself, I would think....

More likely you have calculation turned off, to turn back on
Application.Calculation = xlCalculationAutomatic

or use Tools, calculation (tab), calculation: automatic

Often gets turned of by a macro (or addin) that turns calculation
off, but neglects to restore calculation upon exiting or abnormal termination.

If it is the BLPH function you are using F2 on,
perhaps you have a space before the equal size, check
to see what =ISTEXT(C3) if C3 is the cell address function is in
If it shows Text then it is not recognized as a function by as text.

If it is a constant that you use F2 then enter on and it then works
it might be because you changed the format, or because you have
spaces or non-breaking spaces coming from
HTML so cells are not recognized as numbers until they are reentered
so I would suggest running the TRIMALL macro
http://www.mvps.org/dmcritchie/excel/join.htm
this will change constants not formulas.

HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm
 
Try This Approach ...

Option Explicit
Private Sub Juke_XL_F2_And_BLP()
On Error GoTo eh:

Dim wbName As String
Dim wsName As String
Dim tgt As Worksheet
Dim rng As Range
Dim cell As Range
Dim myString As String
Dim lastRow As Long
Dim lastColumnIndex As Long
Dim lastColumnString As String

wbName = ThisWorkbook.Name
wsName = Workbooks(wbName).ActiveSheet.Name

Set tgt = Workbooks(wbName).Worksheets(wsName)

With tgt
'
'Parameterize the range of interest ...
'
lastRow = FindLastRow
lastColumnIndex = FindLastColumnIndex
lastColumnString = FindLastColumnString
'
'Option A: Finesse the Excel / {F2}{Enter} / BLP cross dependency ...
'
' Start in column D as I want to preserve the formulas in
' columns A and B; use columnIndex = 4 in the formulas below.
'
' Try ...
' Courtesy of ... http://www.ozgrid.com/VBA/SpeedingUpVBACode.htm
'
' Everything:
' Sheet1.Range("A1:A200").Copy Destination:=Sheet2.Range("B1")
'
' Values Only:
' Sheet2.Range("B1:B200").Value = Sheet1.Range("A1:A200").Value
'
' Formulas Only:
' Sheet2.Range("B1:B200").Formula = Sheet1.Range("A1:A200").Formula
'
'Juking the Excel / {F2}{Enter} / BLP interface here ...
'
'tgt.Range(Cells(1, 4), Cells(lastRow, lastColumnIndex)).Value = _
tgt.Range(Cells(1, 4), Cells(lastRow, lastColumnIndex)).Value
'Application.CalculateFull
'
'Option B: Finesse the Excel / {F2}{Enter} / BLP cross dependency ...
' Start in column D as I want to preserve the formulas in
' columns A and B; use columnIndex = 4 in the formulas below.
'
Set rng = Range(Cells(1, 4), Cells(lastRow, lastColumnIndex))
For Each cell In rng

'Range value our string formulas ...
cell.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=False

'Clear the clipboard ...
Application.CutCopyMode = False

'Juking the Excel / {F2}{Enter} / BLP interface here ...
myString = Selection
Selection = myString

Next cell
Application.CalculateFull
'
'In case, you're wondering, the SendKeys approach did not work for me
'
'avoidloop = True
'Application.SendKeys "{F2}", True
'Application.SendKeys "{ENTER}", True

End With

Exit Sub
eh: If Err Then MsgBox "Err[" & Err.Number & "]: " & Err.Description & ".", vbAbortRetryIgnore, "Error Handler": Resume Next
End Sub
Function FindLastRow() As Long
On Error GoTo eh:

Dim theRow As Long

If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
theRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'MsgBox theRow
End If
FindLastRow = theRow

Exit Function
eh: If Err Then MsgBox "Err[" & Err.Number & "]: " & Err.Description & ".", vbAbortRetryIgnore, "Error Handler": Resume Next
End Function
Function FindLastColumnString() As String
On Error GoTo eh:

Dim theColumnIndex As Integer
Dim theColumnString As String
Dim rng As Range
Dim address As String
Dim index As Integer

If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Columns.
theColumnIndex = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
'MsgBox theColumn
End If

Set rng = Range(Cells(1, theColumnIndex), Cells(1, theColumnIndex))
address = rng.address(1, 0)
index = InStr(1, address, "$", vbTextCompare)
theColumnString = Left(address, index - 1)


FindLastColumnString = theColumnString

Exit Function
eh: If Err Then MsgBox "Err[" & Err.Number & "]: " & Err.Description & ".", vbAbortRetryIgnore, "Error Handler": Resume Next
End Function
Function FindLastColumnIndex() As Long
On Error GoTo eh:

Dim theColumnIndex As Integer
Dim theColumnString As String
Dim rng As Range
Dim address As String
Dim index As Integer

If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Columns.
theColumnIndex = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
'MsgBox theColumn
End If

Set rng = Range(Cells(1, theColumnIndex), Cells(1, theColumnIndex))
address = rng.address(1, 0)
index = InStr(1, address, "$", vbTextCompare)
theColumnString = Left(address, index - 1)


FindLastColumnIndex = theColumnIndex

Exit Function
eh: If Err Then MsgBox "Err[" & Err.Number & "]: " & Err.Description & ".", vbAbortRetryIgnore, "Error Handler": Resume Next
End Function
 
F2 and Enter

Find and replace "=" has solved my problem with formula.

With number or date I use to multiply it with 1 to get the resulut
 
Back
Top