vba Run Time error '-2147221080(800401a8), Method 'Cells' of object'_Workdsheet' Failed

m_vishal_c

Board Regular
Joined
Dec 7, 2016
Messages
209
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
HI i have below code and it gives "" Run Time error '-2147221080(800401a8), Method 'Cells' of object'_Workdsheet' Failed "" . please guide

Code:
Private Sub CommandButton1_Click()


Dim xlBook As Workbook
Dim xlNewBook As Workbook
Dim xlSheet As Worksheet
Dim LastRow, myrow, lastColumn, rowPointer As Long
Dim MergeSheet, RocSheet As Worksheet
Dim MergeWorkbook As Workbook
Dim RocWorkbook As Workbook


Dim i As Long


Const strPath As String = "D:\TestFolder\New"
Const strROC As String = "D:\TestFolder\New\New ROC Template 22-12-17.xlsx"
Const strMerge As String = "D:\TestFolder\New\2COO-67 ROC Merge file.xlsx"
Set MergeWorkbook = Workbooks.Add(strMerge)
'Set MergeWorkbook = Workbooks(strMerge)
Set RocWorkbook = Workbooks.Add(strROC)


Set MergeSheet = MergeWorkbook.Worksheets("Sheet1")
Set RocSheet = RocWorkbook.Worksheets("Roc Template")


LastRow = MergeSheet.Cells(Rows.Count, "a").End(xlUp).Row
myrow = 2
    
       
    For rowPointer = 1 To LastRow
        
        'Set xlNewBook = Workbooks.Add(Template:=strFileB)
            RocSheet.Cells(2, 4).Value = MergeSheet.Cells(myrow, 1).Value
            RocSheet.Cells(3, 4).Value = MergeSheet.Cells(myrow, 2).Value
            RocSheet.Cells(4, 4).Value = MergeSheet.Cells(myrow, 3).Value
            'RocWorkbook.SaveAs strPath & CStr(RocSheet.Range("D" & 3)) & ".xlsx"
            RocWorkbook.SaveAs strPath & CStr(RocSheet.Range("D3")), 51
            RocWorkbook.Close 0
            Set RocWorkbook = Nothing
            myrow = myrow + 1
            
           
    Next rowPointer
     


End Sub

heaps thanks in advance
 
Last edited by a moderator:
Re: how to solve vba Automation run time error '-2147221080 (800401a8)

@m_vishal_c

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread. Please read rule 12 here: Forum Rules.
And whilst you are reading the rules please note what RoryA said in post#7
I have merged both threads
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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