Consulting

Results 1 to 2 of 2

Thread: Cells method advice

  1. #1
    VBAX Regular
    Joined
    Jul 2005
    Posts
    74
    Location

    Cells method advice

    When running this code:
    [VBA]
    Set shtrng1 = Sheets("data").Range("a1").CurrentRegion

    Sheets("data").Activate
    c = shtrng1.Columns.Count
    d = shtrng1.Rows.Count
    'Set myrange = Nothing
    For i = 3 To c
    Set myrange = Sheets("data").Range(Cells((d-30), i), Cells(d, i))[/VBA]

    Not the complete code obviously.

    I get an Application or object error at the Set myrange line unless the Sheets("data").Activate line has run, ie it only works if "data" is the active sheet.
    What am I doing wrong?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With Sheets("data")
    For i = 3 To c
    .Range(.Cells((d-30), i), .Cells(d, i))
    ...
    Next i
    End With
    [/vba]

Posting Permissions

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