Modify macro to select specific cells and copy them to specific cells in another sheet

caligirl626

New Member
Joined
Nov 28, 2022
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Have a workbook with many sheets that logs work orders per project (each sheet is a different project). The first sheet called "Project" is the main log that tracks all the work orders.
I need a macro that copies the contents of cell columns A,B,C of a project sheet where the selection has been set to column A, and copies those A,B,C contents into to the "Project" sheet columns D,E,F of the next empty row.

For example, cell A11 is selected in project sheet "6402-01" (capture1.png). When the macro is activated, it copies A11, B11, C11 and pastes them into the "Project" sheet cells D2266, E2266, F2266 because that was the next empty row of the "Project" sheet" (capture2.png).

This code does the request, but only for certain cells. Need it a bit smarter.

VBA Code:
Sub Macro6()
'
' Macro6 Macro
'

'
    Range("A11:C11").Select
    Selection.Copy
    Sheets("Project").Select
    Range("D2266").Select
    ActiveSheet.Paste
End Sub
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    38.3 KB · Views: 12
  • Capture2.PNG
    Capture2.PNG
    23.8 KB · Views: 12

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this on a copy of your workbook.
VBA Code:
Option Explicit
Sub caligirl626()
    Dim ws As Worksheet
    Set ws = Worksheets("Project")
    If ActiveCell.Column = 1 Then
        ActiveCell.Resize(1, 3).Copy ws.Range("D" & ws.Cells(Rows.Count, "D").End(xlUp).Row + 1)
    End If
End Sub
 
Upvote 0
Very nice! Can it be set to land on the "Project" sheet, the cell in column G of that line it just pasted the data in? That would be great!
 
Upvote 0
Can it be set to land on the "Project" sheet, the cell in column G of that line it just pasted the data in
The code already copies to the Project sheet. Do you want it copied to column G of the Project sheet, and not column D as per your original post?
 
Upvote 0
The code already copies to the Project sheet. Do you want it copied to column G of the Project sheet, and not column D as per your original post?
Oh, the code is fine as is! I was just requesting that the cursor ends up in the Column G of that line it copied to in the Project sheet. In other words, place the cursor back to the Project sheet, in the (empty) column G cell, same row as the freshly copied data.
 
Upvote 0
Understood :)
Try this:
VBA Code:
Option Explicit
Sub caligirl626()
    Dim ws As Worksheet
    Set ws = Worksheets("Project")
    If ActiveCell.Column = 1 Then
        ActiveCell.Resize(1, 3).Copy ws.Range("D" & ws.Cells(Rows.Count, "D").End(xlUp).Row + 1)
    End If
    Application.Goto ws.Range("G" & ws.Cells(Rows.Count, "D").End(xlUp).Row)
End Sub
 
Upvote 0
Solution
Hi again! Tried it this morning on my actual spreadsheet and noticed something. When the values are being copied over, it's bringing up errors because I think it's trying to copy over the formulas. Perhaps it needs a paste special command or something like that. Can the code be modified for copying only the values? thanks!
 
Upvote 0
No worries, try this:

VBA Code:
Option Explicit
Sub caligirl626_V2()
    Dim ws As Worksheet
    Set ws = Worksheets("Project")
    If ActiveCell.Column = 1 Then
        ActiveCell.Resize(1, 3).Copy
        ws.Range("D" & ws.Cells(Rows.Count, "D").End(xlUp).Row + 1).PasteSpecial xlPasteValues
        Application.CutCopyMode = False
    End If
    Application.Goto ws.Range("G" & ws.Cells(Rows.Count, "D").End(xlUp).Row)
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,984
Members
449,092
Latest member
Mr Hughes

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