Macro to paste data in the next empty collumn

himurah182

New Member
Joined
Aug 4, 2022
Messages
21
Office Version
  1. 2019
Platform
  1. Windows
Hey guys,
I need your help on this one.
What is the code to paste data in a specific range in the next empty collumn?
I tried this but it keeps pasting the data on the same range, which is on collumn E (look below). Also, how do I make it paste the new data always in collumn E, so older pastes move 1 collumn to the right. In other words, more recent pastes should always be visible in collumn E.
Sub Macro2()

Range("D5:D75").Select
Selection.Copy
Range("C5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("C5").Select
ActiveCell.Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveCell.Offset(0, 2).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
1659604839047.png
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to the Board!

You cut off the row numbers in your image, so we cannot tell which row is row 5.
Can you tell us what is it exactly that you are trying to copy and to what range (in your example)?
 
Upvote 0
Your code and image don't seem to make sense.
Your code looks like it is trying to copy stuff from range D5:D75, but your image shows nothing in that range.

So, please do what I ask in the previous post. Please be sure to give exact cell addresses in your explanation!
Can you tell us what is it exactly that you are trying to copy and to what range (in your example)?
 
Upvote 0
The image shows nothing in that range because I haven’t filled it yet.
When I have it filled I want to copy it and paste it on e5:e75.Also, when I have new data I want it to be pasted on e5:e75. This means that the data that was there before should be moved one column to the right, thus data that on e5:e75 will be on f5:f75.
 
Upvote 0
See if this does what you want:
VBA Code:
Sub MyCopy()

    Dim lc As Long
    
'   Find last column in row 5 with data
    lc = Cells(5, Columns.Count).End(xlToLeft).Column
    
'   Copy data from last column over one column to right
    Range(Cells(5, lc), Cells(75, lc)).Copy
    Cells(5, lc + 1).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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