Sherifa

New Member
Joined
Oct 23, 2017
Messages
45
RUN-TIME ERROR '91'
Object variable or With block variable not set

Code:
[COLOR=#333333]Sub SummaryRow()Dim Wkb As Excel.Workbook[/COLOR]Dim ws As Worksheets
Dim ws_count As Integer
Dim i As Integer
Dim LastRow As Long




    Sheet4.Range("a183:M183").Copy
    
        Set Wkb = ThisWorkbook
        ws_count = Wkb.Worksheets.Count
                
                     
        'Begin loop
        For i = 4 To ws_count
              
       
       Set TargetRow = Wkb.Worksheets(i).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
        
        LastRow = Wkb.Worksheets(i).Cells(Rows.Count, 1).End(xlUp).Row


         'Paste Formulas
        TargetRow.PasteSpecial xlPasteFormulas
        [B]ws(i).Cells(LastRow + 1, 7).FormulaR1C1 = "=SUM(R4C7:R" & LastRow & "C7)"
        ws(i).Cells(LastRow + 1, 8).FormulaR1C1 = "=COUNT(R4C8:R" & LastRow & "C8)"
        ws(i).Cells(LastRow + 1, 9).FormulaR1C1 = "=SUM(R4C9:R" & LastRow & "C9)"[/B]
        TargetRow.PasteSpecial xlPasteFormats
        
        Next i
         [COLOR=#333333]End Sub[/COLOR]
 
I want to be able to copy and paste an Excel Chart using vba to set number of worksheets, but to adjust the range for the charts to that particular spreadsheet, but I'm not sure where to start
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Sub CopyCharts()
Dim Wkb As Excel.Workbook
Dim ws As Worksheet
Dim ws_count As Integer
Dim i As Integer


Worksheets(4).ChartObject(4).Activate
Charts(4).Activate


Sheet4.Charts("ALLDeals").Copy


Set Wkb = ThisWorkbook
ws_count = Wkb.Worksheets.Count


'Begin loop
For i = 4 To ws_count

Set TargetSheet = Wkb.Worksheets(i)


TargetSheet.PasteSpecial xlPasteFormulas


Sheet4.Charts("ALLVolume").Copy


For i = 4 To ws_count

Set TargetSheet = Wkb.Worksheets(i)

TargetSheet.PasteSpecial xlPasteFormulas


Next

End Sub
 
Upvote 0
Code:
Sub CopyCharts()Dim Wkb As Excel.Workbook
Dim ws As Worksheet
Dim ws_count As Integer
Dim i As Integer




Sheet4.ChartObjects("ALLDeals").Copy


        Set Wkb = ThisWorkbook
        ws_count = Wkb.Worksheets.Count
                
                     
        'Begin loop
        For i = 4 To ws_count
        
        Set TargetSheet = Wkb.Worksheets(i)
                        
        TargetSheet.ChartObjects("ALLDeals").Paste
        
        
Sheet4.ChartObjects("ALLVolume").Copy
                           
         TargetSheet.TargetSheet.ChartObjects("ALLVolume").Paste


      Next
      
End Sub
 
Upvote 0
Code:
Sub CopyCharts()Dim Wkb As Excel.Workbook
Dim ws As Worksheet
Dim ws_count As Integer
Dim i As Integer








        Set Wkb = ThisWorkbook
        ws_count = Wkb.Worksheets.Count
                
                     
        'Begin loop
        For i = 4 To ws_count
        
        Set TargetSheet = Wkb.Worksheets(i)
        Sheet4.ChartObjects("ALLDeals").Copy
                        
        TargetSheet.Charts("ALLDeals").Paste
        
        
        Sheet4.ChartObjects("ALLVolume").Copy
                           
        TargetSheet.Charts("ALLVolume").Paste


      Next
      
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

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