Consulting

Results 1 to 4 of 4

Thread: VBA Current region minus header and last column

  1. #1

    VBA Current region minus header and last column

    I have code to minus header row from current region but I need to select current region minus header row and last column. Can anyone help?

    Here is my current code

    Selection.CurrentRegion.Select
    Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select


    So say my current region is Rows 1 through 20 and columns A through H I would need the selection to capture rows 2 through 20 and columns A through G.

    The data won't always be 1-20 and A-G sometime more rows and more columns so I need to be able to do it from current region and minus out the first row and last column.

    Thanks!!

  2. #2
    sub M_snb()
      with cells(1).currentregion
        .offset(1).resize(.rows.count-1,.columns.count-1).select
      end with
    End sub

  3. #3
    Quote Originally Posted by snb View Post
    sub M_snb()
      with cells(1).currentregion
        .offset(1).resize(.rows.count-1,.columns.count-1).select
      end with
    End sub

    THANK YOU!!!! Works perfect!!!

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    code fragment with some commented testing statements

    no error traps so if for example the selected cell has nothing else in the current region, it will error

    Option Explicit
    Sub test()
    '    ActiveSheet.Range("E5:z26").Value = 1234
    '    ActiveSheet.Range("M13").Select
    '    MsgBox Selection.Address
        
        With Selection.CurrentRegion
        
    '        MsgBox Selection.CurrentRegion.Address
            .Cells(2, 1).Resize(.Rows.Count - 1, .Columns.Count - 1).Select
    '        MsgBox Selection.Address
        
        End With
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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