Insert Cells into Defined Range in middle of sheet surrounded with data

KimC33

New Member
Joined
Aug 31, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
In my spreadsheet, I have a set of data at the top (14 lines (A5:J56)) "Current Month". I need to copy this data and insert it in a defined range "Full History" starting in row 46. Its basically monthly data that I am copying down so each month it will be another 14 lines down since the last time the macro was run. There is data after this defined range too including a pivot table. I also have data on the right side so cannot insert rows. How do you write the code to insert the cells in the range (A5:J56) at the end of the range B47:L102? And then at the end of that range, each month going forward? Dont see how to attach the sample Excel file so here are a few screenshots of the sample file for your reference. thanks for the help.
 

Attachments

  • Sample mr excel 1.jpg
    Sample mr excel 1.jpg
    148.6 KB · Views: 8
  • Sample mr excel 2.jpg
    Sample mr excel 2.jpg
    216.8 KB · Views: 8
  • Sample mr excel 3.jpg
    Sample mr excel 3.jpg
    206.9 KB · Views: 8

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I am assuming that you made a typo in your story, and that the input range to be copied to the history sheet is A5:J18

VBA Code:
Option Explicit


'//// Macro to copy current month to the Full History sheet, appending to history data \\\\
Sub TransferMonth()
    Dim wsMonth As Worksheet, wsHist As Worksheet
    Dim lRin As Long, lRout As Long
    Dim rIn As Range, rOut As Range
    
    ' to make maintenance easy,have some worksheet variables set to the two sheets
    Set wsMonth = Sheets("Current Month")
    Set wsHist = Sheets("Full History")
    
    ' set the input range to theinput range on wsMonth
    With wsMonth.Range("A4").CurrentRegion
        Set rIn = wsMonth.Range("A5").Resize(.Rows.Count - 1, .Columns.Count)
    End With
    
    ' set the output range to the end of the range starting at B46 on the full history sheet
    lRout = wsHist.Range("B46").End(xlDown).Row + 1
    Set rOut = wsHist.Range("B" & lRout).Resize(rIn.Rows.Count, rIn.Columns.Count)
    
    ' Now copy the values from the input range to the history output range
    rOut.Value = rIn.Value
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top