Copy Paste Macro

NPandelos

New Member
Joined
May 3, 2022
Messages
12
Office Version
  1. 365
Please bare with me on this. I'm looking for some help with a copy paste macro I'm trying to write.

What I'm trying to do is look to see if there is a value in the "Stock Code" column. If there is look at the "Item Type & Action" columns depending on those values.
1661335593274.png

The "release" would have the cell cell value paste-text into the first blank cell in a different sheet.
1661342320849.png

If it is "change" the cell value would be paste-text into the first two blank cells in different sheet.
1661342351166.png


So far this is my code, but I am unsure what to put for the ranges.

Sub CopyStockCodeUpdates()
'
' CopyStockCodeUpdates Macro
Dim scNum, scCount As Integer
Dim scCurrent, sheetCurrent As String

Application.ScreenUpdating = False

Sheets("Engineering Input Form").Select
Range("B6").Select
'scCount = 0
scNum = 1

'Is there a stock code in the current cell? If so, continue.
While ActiveCell.Value <> ""
'Is this line a RELEASE? If so, copy active cell & paste text to "New Stock Code"
If Range("D" & (ActiveCell.Row)).Value = "SC - STOCK CODE" And Range("F" & (ActiveCell.Row)).Value = "RELEASE" Then
Selection.Copy
Sheets("New Stock Code").Select
Range ()
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Is this line a CHANGE? If so, copy active cell & paste text to "Stock Code Updates"
If Range("D" & (ActiveCell.Row)).Value = "SC - STOCK CODE" And Range("F" & (ActiveCell.Row)).Value = "RELEASE" Then
Selection.Copy
Sheets("Stock Code Updates").Select
Range()
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
End If

scNum = scNum + 1
Sheets("Worksheet").Select
ActiveCell.Offset(1, 0).Select
Wend

Application.ScreenUpdating = True

End Sub

Any help would be greatly appreciated.
 
That work. Thank you.

So I didn't need to put in a while loop. I just needed to declare the stock code (SC) as a range, then swap out active cell w/ SC.
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You are very welcome. :) I used the SC variable to loop through the range.
 
Upvote 0
I have reworked the code you helped me with to put everything onto one sheet. Now in addition to the copy/paste I want to change the cell color (see image below). The cell fill only needs to change when "release" is in the one column. How would I do that? I've searched and everything I've found doesn't seem to work.

VBA Code:
Sub Copy_Data()
    Application.ScreenUpdating = False
    Dim SC As Range
    For Each SC In Range("B5", Range("B" & Rows.Count).End(xlUp))
        If SC.Offset(, 2) = "SC - STOCK CODE" And SC.Offset(, 4) = "RELEASE" Then
            With Sheets("Stock Code Updates")
                .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Resize(2) = SC
            End With
        ElseIf SC.Offset(, 2) = "SC - STOCK CODE" And SC.Offset(, 4) = "CHANGE" Then
            With Sheets("Stock Code Updates")
                .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Resize(2) = SC
            End With
        End If
    Next SC
    Application.ScreenUpdating = True
    
    MsgBox ("The stock codes have been copied over to the Stock Code Update worksheet.")
    
End Sub

Proposed MDM.xlsm
ABCD
2Stock CodeAbcAnalysisReqAbcCostingReq
3From507610-00YN
4To507610-00
5FromTP.1234.567??
6ToTP.1234.567
7From507611-00YN
8To507611-00
9From507612-00YN
10To507612-00
11From507613-00YN
12To507613-00
13FromTP.5678.900??
14ToTP.5678.900
15FromTP.6789.999??
16ToTP.6789.999
Stock Code Updates
 
Upvote 0
In the picture you posted, there are three different colors. Also, there is no distinct pattern as to which rows receive which color. Could you clarify in detail which color you want to use and the criteria used to determine which rows receive that color.
 
Upvote 0
Please ignore the last post. I ended up using conditional formatting to achieve what I wanted.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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