Excel vba copy paste to next empty column

hatman

I have calculations and texts in cells D8:E30. I want to create button for copying Range of D8:E30 with all fill colors, borders, formulas and texts as they are and paste to next empty column. At the starting point F8 is the first one where D8:E30 range can be copyed. By pressing the button D8:E30 is copyed to F8, then by pressing the button again D8:E30 is copyed to the next empty column and it will be H8... and so on. I managed to come up with the code below but it is inserting to the next empty ROW (veryically) I need it to be next empty Column (horizontally). Can anyone help with this one? Thank you!

Sub CopyPaste()
Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet

Set copySheet = Worksheets("Price calculation")
Set pasteSheet = Worksheets("Price calculation")

copySheet.Range("D8:E30").Copy
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulas

Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Mr ML

This part of your code decides where to paste:

pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)

Broken down: Right now it is set to go from cell (1048576, 1)

pasteSheet.Cells(Rows.Count, 1)

and up until it finds a cell which is not blank.

.End(xlUp)

Offset just offsets the cell value by 1 row. (E.g. if last blank row is 12 it will paste to cell 13)

.Offset(1, 0)

What you need is:

pasteSheet.Cells(1, columns.count).End(xlToLeft).Offset(0, 1)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Excel VBA: filter list for "empty" (failed matching) values then copy and paste to new column Code loop

Excel VBA Copy Paste

Copy & paste on VBA excel

Excel VBA to Copy Multiple Ranges and paste to another sheet, no empty rows

Excel VBA Copy and Paste (without using Copy+Paste functions) on empty row

excel vba: How to paste the combobox value to the next column cell

Excel VBA Copy & Paste a Range of Cells Repeatedly in a Column

excel vba macro: copy and paste the specific column to another workbook

Excel VBA to Copy Every Column in a Sheet to the Next Column to the Right

A Copy Paste Fail Excel VBA

Excel VBA: Compley copy & paste

Excel VBA copy paste then format

copy paste Range in VBA Excel

Excel VBA Copy file but NOT paste

Copy paste using VBA in excel

Copy paste as values Excel VBA

Copy and Paste data into next empty row

How to copy the values from the same column into the next columns? Excel VBA

VBA Excel Macro find column name and next need to copy range

copy and paste next without for vba error

Select next non empty cell in A column - Excel VBA

Google Sheets Apps Script: if a neighboring checkbox is checked then copy and paste that cell to the next empty cell of another column

Trying to copy a range from one sheet and paste it to the next empty cell in a column on another sheet

Excel macro to copy values from certain cells and paste them into next empty cells

Copy Paste Data into First empty Row VBA

Copy and paste cell to the next column based on a condition

Copy Only Cells From Visible Sheets And Paste Into Next Free Column VBA

Excel VBA Find Row, copy contents, paste in next sheet then delete original data

How can I delete empty cells in Excel using VBA after a Copy/Paste?