Question : Clear only first 5 columns

Hi guys,

I am still working on this macro just trying to twik it a bit. (sorry for the messiness of my commenting)

Is there a way I can get line 23 to only check the first 6 columns for used data?  I am wanting to put formals in column G but as soon as I do the data starts populating from below my lowest formula.

Cheers,
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
'This sub must be installed in the code pane for the calendar worksheet. It will not work at all if installed anywhere else.
Private Sub Worksheet_Activate()
Dim ws As Worksheet, wsCalendar As Worksheet
Dim rg As Range, rgDest As Range
Dim n As Long
'Application.ScreenUpdating = False
Set wsCalendar = Worksheets("Calendar")
wsCalendar.Range("a2", "f10000").Clear
'wsCalendar.Rows(2).Resize(wsCalendar.Rows.Count - 1).ClearContents
'wsCalendar.Rows.ClearContents
For Each ws In ThisWorkbook.Worksheets
    Select Case ws.Name
    Case "Calendar", "Home", "Working Space"   'Ignore these worksheets
    Case Else
        With ws
            'ws.Activate
            Set rg = .Range("B4").Resize(.UsedRange.Rows.Count, 5)    'Look at columns B:F, starting in row 4
            If (Not Intersect(rg, .UsedRange) Is Nothing) And (rg.Cells(2, 1) <> "") Then
                'rg.AutoFilter Field:=2, Criteria1:="<=" & (Date + 5), Operator:=xlAnd, Criteria2:=">=" & (Date - 5)
                'must be US date format
                today = Format(Date, "mm-dd-yyyy")
                rg.AutoFilter Field:=2, Criteria1:=">=" & today ', Operator:=xlAnd, Criteria2:=">=" & plus5days
                Set rgDest = wsCalendar.Cells(wsCalendar.UsedRange.Rows.Count + wsCalendar.UsedRange.Row, 2)
                .AutoFilter.Range.Copy rgDest
                n = wsCalendar.UsedRange.Rows.Count + wsCalendar.UsedRange.Row - rgDest.Row
                rgDest.Offset(0, -1).Resize(n, 1).Value = ws.Name
                rgDest.Rows(1).EntireRow.Delete
                .Range("B4").AutoFilter
            End If
        End With
    End Select
Next
Application.ScreenUpdating = True
End Sub

Answer : Clear only first 5 columns

A lot of times you get #Name with common functions like Date(), Len() ... etc if ... a Reference is missing.

VBA editor >> Tools>>References.  Look for any listed as
**Missing <SomeReferenceName>

mx
Random Solutions  
 
programming4us programming4us