Magnifying The Selected Cell

Excel VBA Zoom In Cell

         We've created a magnifying glass that magnifies the image within the worksheet. Thus,values in the selected cell or cells is displayed as 1.75 times larger.

For to magnify the cell's view the following solution can be applied :
✔️ We have created a procedure called Zoom_Cells and assigned this procedure to the       Worksheet_SelectionChange event of Sheet1.

✔️ With the codes that we add to the Worksheet_SelectionChange event of the Sheet1, as automatic a 1.75-fold larger image of the selected cells is created.

  Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub

Sub Zoom_Cells()
    Dim sel As Range, cell As Range, Zoom_In As Single
    Set sel = Selection
    Zoom_In = 1.75                         'Zoom rate
  For Each cell In Selection               'If there are blank cells in selection, shapes are deleted and ended method
        If cell.Value = Empty Then
        Call remove_picture
        GoTo here:
         Exit Sub
         End If
 Call remove_picture                        'Remove any existing zoom pictures
  Application.ScreenUpdating = False
    sel.CopyPicture Appearance:=xlScreen, Format:=xlPicture      'Create zoom picture
   With Selection
        .Name = "Zoom_Cells"
      With .ShapeRange
            .ScaleWidth Zoom_In, msoFalse, msoScaleFromTopLeft
            .ScaleHeight Zoom_In, msoFalse, msoScaleFromTopLeft
          With .Fill
                .ForeColor.SchemeColor = 44
                .Visible = msoTrue
                .Transparency = 0
            End With
        End With
    End With
    Application.ScreenUpdating = True
    Set sel = Nothing
End Sub
Sub remove_picture()                           'Remove any existing zoom pictures
Dim k As Object
For Each k In ActiveSheet.Pictures
        If k.Name = "Zoom_Cells" Then
        End If
End Sub

✔️ When an empty cell is selected, the image is removed and the procedure is terminated.

No comments:

Post a Comment