0
votes

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.

  1. To find the range starting from cell A2 in each sheet (except 2 sheets).
  2. 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`

1
What is this supposed to be doing: getLastCell(ws4) when getLastCell is a range, not a function? Also, remove the .Select from the Set shtrng = lineRory
@Rory Honestly I have no clue. I copied this from a tutorial example on range. can you suggest me modification to this code?. thanksSri

1 Answers

0
votes

Change this:

Set shtrng = ActiveSheets.Range("A1", getLastCell(ws4)).Select

to this:

ActiveSheet.Range("A1", getLastCell).Select