macro help

david graham

Active Member
Joined
Dec 6, 2007
Messages
345
Anyone know how to modify the code below to replace the current content of each cell with a "0" (instead of clearing it)?


Code:
    Dim g As Range, v As Range, vu As Range, c As Range
    
    Set g = Intersect(Range(ActiveSheet.ScrollArea), Columns("D:J"))
    If Not g Is Nothing Then
        On Error Resume Next
        Set v = g.SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
        If Not v Is Nothing Then
            For Each c In v
                If Not c.Locked Then
                    If vu Is Nothing Then
                        Set vu = c
                    Else
                        Set vu = Union(vu, c)
                    End If
                End If
            Next c
            If Not vu Is Nothing Then
                With vu
                    .ClearContents
                    .Cells(1).Select
                End With
            Else
                MsgBox "No visible, unlocked cells in scroll area in col G"
            End If
        Else
            MsgBox "No visible cells in scroll area in col G"
        End If
    Else
        MsgBox "Scroll area does not intersect with col G"
    End If
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
see bold red:

Rich (BB code):
Dim g As Range, v As Range, vu As Range, c As Range
    
    Set g = Intersect(Range(ActiveSheet.ScrollArea), Columns("D:J"))
    If Not g Is Nothing Then
        On Error Resume Next
        Set v = g.SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
        If Not v Is Nothing Then
            For Each c In v
                If Not c.Locked Then
                    If vu Is Nothing Then
                        Set vu = c
                    Else
                        Set vu = Union(vu, c)
                    End If
                End If
            Next c
            If Not vu Is Nothing Then
                With vu
                    .Value = 0
                    .Cells(1).Select
                End With
            Else
                MsgBox "No visible, unlocked cells in scroll area in col G"
            End If
        Else
            MsgBox "No visible cells in scroll area in col G"
        End If
    Else
        MsgBox "Scroll area does not intersect with col G"
    End If
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,058
Latest member
oculus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top