Consulting

Results 1 to 4 of 4

Thread: Object Variable or With Block variable not set

  1. #1

    Object Variable or With Block variable not set

    Hi, I have written the code below but for some reason the line highlighted in bold gives the error "Object Variable or With Block variable not set". Any help on how to solve this would be much appreciated. Thanks in advance

    Sub PreviousDay()
        Dim CalcsNew As Worksheet
        Set ClacsNew = ThisWorkbook.Worksheets("Calcs New")
    Dim ContractSide As Range
    With CalcsNew
            Set ContractSide = .Range(CalcsNew.Range("D33"), CalcsNew.Range("D65000").End(xlUp))
    For Each CellContractSide In ContractSide
            If CellContractSide.Value = "Long" Then
                CellContractSide.Offset(0, 7).Copy
                CellContractSide.Offset(0, 9).PasteSpecial.Values
            Exit For
        End If
    Next
    For Each CellContractSide In ContractSide
            If CellContractSide.Value = "Short" Then
                CellContractSide.Offset(0, 7).Copy
                CellContractSide.Offset(0, 9).PasteSpecial.Values
            Exit For
        End If
    Next
    End With
    End Sub
    Last edited by Aussiebear; 09-17-2013 at 05:13 AM. Reason: wrapped code with tags

  2. #2
    VBAX Contributor GarysStudent's Avatar
    Joined
    Aug 2012
    Location
    Lakehurst, NJ, USA
    Posts
    127
    Location
    Check your spelling:


    ClacsNew
    is not
    CalcsNew
    Have a Great Day!

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Sub PreviousDay() 
       For Each cl in ThisWorkbook.sheets("Calcs New").columns(4).specialcells(2) 
         If cl.row>32 and (cl = "Long" or cl="Short") Then cl.offset(,9)=cl.Offset(, 7).value 
       Next 
    End Sub

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    CellContractSide.Offset(0, 9).PasteSpecial xlPasteValues
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •