Export sheet changing empty string ("") to BLANK()
04:57 10 Oct 2025

The code is designed to export data from the sheet "Export" to a new workbook that should then be loaded in an external online tool.

The sheet "Export" is based on the standard template of the external tool that cannot be changed:
rows 1&2 header
cells A3:B102 information to be loaded in the tool.

"Export" gets information from another sheet of the workbook and formulas in the cells of the range A3:B102 return either a text/number or "", depending if they are populated or not.

The new workbook is correctly generated, however the external tool is not able to manage empty strings and it returns blocking errors.

The need is to avoid exporting the empty strings in the range A3:B102 when there are no text/value to be saved and change them to the equivalent of BLANK(), that I cannot embed in the formulas as not existing function in Excel.

E.g. the formula for cell A3 is =IF(Sheet1!F12<>"",Sheet1!G12,"")

Private Sub CommandButton1_Click()
    Dim wbkS As Workbook
    Dim wbkT As Workbook
    Dim wshS As Worksheet
    Dim wshT As Worksheet
    Dim varN As Variant
    Dim strA As String
    Application.ScreenUpdating = False
    Set wbkS = ActiveWorkbook
    Set wbkT = Workbooks.Add(xlWBATWorksheet)
    wbkT.Worksheets(1).Name = "Something Improbable"
    For Each varN In Array("Export")
        Set wshS = wbkS.Worksheets(varN)
        Set wshT = wbkT.Worksheets.Add(After:=wbkT.Worksheets(wbkT.Worksheets.Count))
        wshT.Name = varN
        strA = wshS.UsedRange.Cells(1, 1).Address
        wshS.UsedRange.Copy
        wshT.Range(strA).PasteSpecial Paste:=xlPasteValues
    Next varN
    Application.DisplayAlerts = False
    wbkT.Worksheets(1).Delete
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

I tried to find alternative ways to avoid the "" in the IF function, but considering the way the Excel file is structured there is no way to change the formula. Therefore I need to edit the VBA code.

excel vba