Copy and paste into active cell

londa_vba

Board Regular
Joined
May 11, 2023
Messages
61
Office Version
  1. 365
Platform
  1. Windows
Hello
I want to be able to choose any cell in column A (A9) on active sheet "CE" and have a macro button then copy ranges "B8:B33,B39:B64,B70:B95,B101:B126" from sheet "YPF" and paste them into active sheet active cell plus 27(?) columns to the right (AA9) on sheet ("CE")
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
If you want to copy everything:

VBA Code:
Sub Copy_and_paste_into_active_cell()
  If ActiveCell.Column <> 1 Then
    MsgBox "Select a cell in column A"
    Exit Sub
  End If
  Sheets("YPF").Range("B8:AC33,B39:AC64,B70:AC95,B101:AC126").Copy ActiveCell
End Sub

Or simply values:

VBA Code:
Sub Copy_and_paste_into_active_cell_V2()
  If ActiveCell.Column <> 1 Then
    MsgBox "Select a cell in column A"
    Exit Sub
  End If
  Sheets("YPF").Range("B8:AC33,B39:AC64,B70:AC95,B101:AC126").Copy
  ActiveCell.PasteSpecial xlPasteValues
End Sub

Regards
Dante Amor
 
Upvote 0
If you want to copy everything:

VBA Code:
Sub Copy_and_paste_into_active_cell()
  If ActiveCell.Column <> 1 Then
    MsgBox "Select a cell in column A"
    Exit Sub
  End If
  Sheets("YPF").Range("B8:AC33,B39:AC64,B70:AC95,B101:AC126").Copy ActiveCell
End Sub

Or simply values:

VBA Code:
Sub Copy_and_paste_into_active_cell_V2()
  If ActiveCell.Column <> 1 Then
    MsgBox "Select a cell in column A"
    Exit Sub
  End If
  Sheets("YPF").Range("B8:AC33,B39:AC64,B70:AC95,B101:AC126").Copy
  ActiveCell.PasteSpecial xlPasteValues
End Sub

Regards
Dante Amor
Hello Dante, the message box prompt is awesome but I need the copy range to stay B8:B33,B39:B64,B70:B95,B101:B126 from "YFP" (this wont ever change) and the paste to be in "CE" sheet using the row of the selected cell but over in AA column because I have some hidden formulas out there. So if I select A12 I want it to paste into AA12, if I chose A47 I want it to paste into AA47, etc. I hope that explanation is easier.
 
Upvote 0
So if I select A12 I want it to paste into AA12, if I chose A47 I want it to paste into AA47
Try:

VBA Code:
Sub Copy_and_paste_into_active_cell()
  If ActiveCell.Column <> 1 Then
    MsgBox "Select a cell in column A"
    Exit Sub
  End If
  Sheets("YPF").Range("B8:B33,B39:B64,B70:B95,B101:B126").Copy Range("AA" & ActiveCell.Row)
End Sub

🫡
 
Upvote 0
Try:

VBA Code:
Sub Copy_and_paste_into_active_cell()
  If ActiveCell.Column <> 1 Then
    MsgBox "Select a cell in column A"
    Exit Sub
  End If
  Sheets("YPF").Range("B8:B33,B39:B64,B70:B95,B101:B126").Copy Range("AA" & ActiveCell.Row)
End Sub

🫡
I am getting a subscript out of range message for line
Sheets("YPF").Range("B8:B33,B39:B64,B70:B95,B101:B126").Copy Range("AA" & ActiveCell.Row)
 
Upvote 0
Check that you have copied the macro correctly:


VBA Code:
Sub Copy_and_paste_into_active_cell()
  If ActiveCell.Column <> 1 Then
    MsgBox "Select a cell in column A"
    Exit Sub
  End If
  Sheets("YPF").Range("B8:B33,B39:B64,B70:B95,B101:B126").Copy Range("AA" & ActiveCell.Row)
End Sub


and the name of the sheet
😬
 
Upvote 0
Check that you have copied the macro correctly:


VBA Code:
Sub Copy_and_paste_into_active_cell()
  If ActiveCell.Column <> 1 Then
    MsgBox "Select a cell in column A"
    Exit Sub
  End If
  Sheets("YPF").Range("B8:B33,B39:B64,B70:B95,B101:B126").Copy Range("AA" & ActiveCell.Row)
End Sub


and the name of the sheet
😬
hmm now it says can't do that in a merged cell
 
Upvote 0
now it says can't do that in a merged cell
You cannot paste a range of cells into a merged cell.
Remove the merged cells and try again.

It is not recommended to use combined cells in data management. You can use them in titles or something like that.

If you don't remove them, you will have problems with any macro.
;)
 
Upvote 0

Forum statistics

Threads
1,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

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