Error with Macro

ian0886

New Member
Joined
Dec 10, 2016
Messages
42
Hi Guys,

I have my macro below. On the line that is bolded and underline, I'm faced with a error message " Object variable or with block variable not set". I can't really figure what's missing in the variables that i've set. Appreciate the help!
Code:
Sub newspread()


    Dim wbMO2 As Workbook
    Set wbMO2 = Workbooks("family.xlsm") 'rem to change to trade tickets
    Dim trg As Worksheet, wsMO2(1 To 4) As Worksheet, colCount As Integer
     
    Set wsMO2(1) = wbMO2.Sheets("BP")
    Set wsMO2(2) = wbMO2.Sheets("TKY")
    Set wsMO2(3) = wbMO2.Sheets("family")


     
    Set trg = wbMO2.Worksheets.Add(After:=wbMO2.Worksheets(wbMO2.Worksheets.Count))
    trg.Name = "Master"
    
    Dim rng(1 To 2) As Range
    Set rng(1) = trg.UsedRange.Find("BNP", , xlValues, xlPart)
    
    For counter = 1 To 2
    With wsMO2(counter)
    .AutoFilterMode = False
    .Range("A2:I60").Copy
    End With
    
    With trg
        .Activate
        .Range("A" & Rows.Count).End(xlUp).PasteSpecial xlPasteValues, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
[U][B][I]        .Range("A1").CurrentRegion.AutoFilter Field:=rng(1).Column, Criteria1:=""[/I][/B][/U]
        .Range("A1").CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        .AutoFilterMode = False
    End With
    Next counter
    
    trg.Range("a1").CurrentRegion.Copy
    
    With wsMO2(3)
        .Range("A2").Insert Shift:=xlDown
        .Columns.AutoFit
        .Columns("F:F").NumberFormat = "0.0000000"
        .Columns("B:B").NumberFormat = "d/mm/yyyy"
        .Columns("I:I").Value = .Columns("I:I").Value
    End With
End Sub
 
Do you have any event code?
Because as Norie said, the code you have supplied is not pasting any data into the trg sheet
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi Norie,

I'm abit lost right now. What i'm trying to achieve is to copy from one sheet to trg. Afterwhich, i want to filter the header BNP and search for all the blanks and delete the blanks.

Subsequently, the next sheet is copied and pasted and the process is repeated. Could you advise how can i amend the macro to achieve this?
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,222
Members
453,024
Latest member
Wingit77

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