I am getting an error message 438, while executing this code.
I have 16 worksheets in my workbook out of which I need to run this dynamic range code for 14 worksheets.
- To find the range starting from cell A2 in each sheet (except 2 sheets).
- And clear the contents of this selected range. *(i dont want to use .usedrange function) the Objective of the Code is:
`Sub DynamicRange()
Dim ws4 As Worksheet
Dim twb As ThisWorkbook
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range
Dim getLastCell As Range
Dim shtrng As Range
'Answer = MsgBox("The file may contain data, which will be lost if you proceed" & vbCrLf & "Save the
'file with a different file name to retain data" & vbCrLf & " Or Click Yes to proceed ", vbQuestion +
'vbYesNo + vbDefaultButton2, "Caution")
'If Answer = vbYes Then
Set twb = Application.ThisWorkbook
For Each ws4 In twb.Worksheets
Set ws4 = ActiveSheet
If ws4.Name <> "Generate Pending Log Report" And ws4.Name <> "PL1.Summary" Then
ws4.Select
LastRow = ws4.Cells.Find("*", ws4.Cells(1, 1), xlFormulas, xlPart, xlByRows, _
xlPrevious).Row
lastCol = ws4.Cells.Find("*", ws4.Cells(1, 1), xlFormulas, xlPart, xlByColumns, _
xlPrevious).Column
Set getLastCell = ws4.Cells(LastRow, lastCol)
Set shtrng = ActiveSheets.Range("A1", getLastCell(ws4)).Select
'I am getting an error 438
End If
Next ws4
'End If
End Sub`
getLastCell(ws4)
whengetLastCell
is a range, not a function? Also, remove the.Select
from theSet shtrng =
line – Rory