Consulting

Results 1 to 3 of 3

Thread: Help Creating Macro for Selection, copying ranges

  1. #1
    VBAX Regular
    Joined
    Jun 2019
    Posts
    44
    Location

    Help Creating Macro for Selection, copying ranges

    Hey guys and gals,

    I'm trying to create a macro that will do the following: select a range from B46 to E46, do the Ctrl+Shft+Down function, copy that selection, and paste it in a new work sheet. Here is how far I've gotten so far:

    Sub DynamicRange()
    'Best used when first column has value on last row and first row has a value in the last column
    Dim sht As Worksheet
    Dim LastRow As Long
    Dim LastColumn As Long
    Dim StartCell As Range
    'Find Last Row and Column
    LastRow = Cells(Rows.Count, StartCell.Column).End(xlUp).Row
    LastColumn = Selection.Resize(Selection.Rows.Count + 5, _
    Selection.Columns.Count).Select
    'Select Range
    Range(Range("B46"), Cells(LastRow, LastColumn)).Select


    Any help with getting it to be completed would be amazing! Thanks all.

    Cheers,

    Baiano42

  2. #2
    VBAX Regular
    Joined
    Jun 2019
    Posts
    44
    Location
    I think I got it to work :

    Range("B46:E46").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets.Add After:=ActiveSheet
    ActiveSheet.Paste
    Rows("2:2").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "B"
    Range("C1").Select
    ActiveCell.FormulaR1C1 = "C"
    ActiveSheet.Name = "Given Name"
    End Sub

  3. #3
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test()
        Dim StartCell As Range
    
        Set StartCell = Range("B46:E46")
        
        With Worksheets.Add
            Range(StartCell, StartCell.End(xlDown)).Copy .Range("A1")
            .Rows(2).Delete
            .Range("b1:c1").Value = Array("B", "C")
            .Name = "Given Name"
        End With
    
    End Sub

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
  •