Macro to copy/paste special values if cel contains

hstef

New Member
Joined
Nov 19, 2018
Messages
39
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I need a macro to copy cells B, C, D, H, I, K, L, M, N, and paste special values if cel contains "success" in column "M".

If I have "success" in M3, then macro to copy B3, C3, D3, H3, I3, K3, L3, M3, N3 and paste special values over the same cells.
If I have "success" in M10, then I need copy paste special values over the same cells (B, C, D, H, I, K, L, M, N) in row 10.

I have formulas in these cells and the result can be changed upon excel cube refresh, which I do not want. Copy/paste special values over the formulas will keep the result I need when "success" occurs.

Can this be done?

Thank you kindly,
Stefan.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi,

If it is easier, the macro to copy entire row.
I "success" is in M3, then the macro to copy paste special values row 3.

Thanks :)
 
Upvote 0
I found a macro, which, after a little adjustment, works:
VBA Code:
Sub InStockMacro()

ActiveSheet.Select
Dim rngA As Range
Dim cell As Range
Set rngA = Range("I1", Range("I10"))
For Each cell In rngA
If cell.Value = "InStock" Then
cell.EntireRow.Select
Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

  Application.CutCopyMode = False
  Range("A1").Select
End If
Next cell

End Sub
 
Last edited by a moderator:
Upvote 0
Solution
I have fixed it for you this time but please use the available code tags when posting vba code. My signature block below has more details.
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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