Consulting

Results 1 to 4 of 4

Thread: Adjust the CurrentRegion when copying

  1. #1
    VBAX Regular
    Joined
    Oct 2006
    Location
    Wiltshire, UK
    Posts
    43
    Location

    Adjust the CurrentRegion when copying

    Hi All

    I am looping through excel workbooks (monthly transaction reports) in a folder, extracting data based on certain criteria (using the autofilter) and using the currentregion property copying that data to my main workbook so I end up with transactions for all months that meet the criteria in 1 worksheet. (see extract below)

    [VBA]

    Cells.CurrentRegion.Copy Destination:=aBook.Range("A1").Offset(x, 0)
    x = aBook.UsedRange.Rows.Count

    [/vba]

    What I would like help with is 'adjusting' the currentregion so I am not copying row1 of the current region (i.e. the title row), but from row 2 down, how can I do this?

    Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    One very simple way

    [vba]

    Intersect(Cells.CurrentRegion, Rows("2:" & Cells.CurrentRegion.Count - 1))
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Oct 2006
    Location
    Wiltshire, UK
    Posts
    43
    Location
    xld

    Again you have come to my rescue. Many thanks.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Whilst the code that I gave you does work, it should have been

    [vba]

    Intersect(Cells.CurrentRegion, Rows("2:" & Cells.CurrentRegion.Rows.Count)).Address
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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