I am creating a new Macro and I getting an error 438. I have tried to create the object but it is still not working. The name of the first worksheet is AMDOCS_DATA. The line highlighted in Blue is what is causing the error.Any help would be appreciated. Tom
Code:
Sub Formatting()
Dim rng As Range
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
'TAB AMDOCS_DATA
ThisWorkbook.Worksheets("AMDOCS_DATA").Select
[BlUE]For Each rng In xlBook.AMDOCS_DATA.Range("H:R").Columns [/BLUE]
rng.TextToColumns
Next rng
'TAB CSG_DATA
For Each rng In CSG_DATA.Range("C:Q").Columns
rng.TextToColumns
Next rng
'TAB AM_DAYS_OUT
For Each rng In AM_DAYS_OUT.Range("D:M").Columns
rng.TextToColumns
Next rng
'TAB CSG_DAYS_OUT
For Each rng In CSG_DAYS_OUT.Range("D:M").Columns
rng.TextToColumns
Next rng
'Delete function
'Delete Columns B-G in worksheet AMSDOCS_DATA
ThisWorkbook.Worksheets("AMDOCS_DATA").Columns("B:G").Delete
'Delete Column A in Worksheet CSG_DATA
ThisWorkbook.Worksheets("CSG_DATA").Columns("A").Delete
'Delete Row 1 in Worksheet CSG_DATA
ThisWorkbook.Sheets("CSG_DATA").Range("1").Delete xlUp
End Sub