Skip to content

Commit f9a6328

Browse files
authored
Merge pull request #26 from bskinn/empty-sheet
Handle idiosyncrasy of .UsedRange on empty sheet
2 parents 08e466b + a9aebac commit f9a6328

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/UFExporter.frm

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,33 @@ Private Sub setExportRange()
365365
' be set to Nothing, which twigs the error-state check in
366366
' setExportEnabled and setExportRangeText
367367

368+
Dim isSheetEmpty As Boolean
369+
370+
' Detect if the sheet is *actually* completely empty
371+
' .UsedRange returns Range($A$1) rather than Nothing, if
372+
' sheet is completely empty
373+
With Selection.Parent
374+
If .UsedRange.Address = "$A$1" And IsEmpty(.UsedRange) Then
375+
isSheetEmpty = True
376+
Else
377+
isSheetEmpty = False
378+
End If
379+
End With
380+
368381
If Selection.Areas.Count <> 1 Then
369382
Set ExportRange = Nothing
370383
Else
384+
' Handle if entire rows or columns (or both) are selected
371385
If Selection.Address = Selection.EntireRow.Address Or _
372-
Selection.Address = Selection.EntireColumn.Address Then
373-
Set ExportRange = Intersect(Selection, Selection.Parent.UsedRange)
386+
Selection.Address = Selection.EntireColumn.Address Then
387+
If isSheetEmpty Then
388+
' There's definitely no content to be intersected with
389+
' the selection! This copes with the above "$A$1" return
390+
' from .UsedRange.
391+
Set ExportRange = Nothing
392+
Else
393+
Set ExportRange = Intersect(Selection, Selection.Parent.UsedRange)
394+
End If
374395
Else
375396
Set ExportRange = Selection
376397
End If

src/UFExporter.frx

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)