if cell contains paste

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » If Cell Contains Paste Value

If Cell Contains Paste Value

resolvedResolved · High Priority · Version 2010

Mark has attended:
Excel VBA Intro Intermediate course
Excel Advanced - For Power Users course
Excel PowerPivot course
Excel Dashboards for Business Intelligence course

If Cell Contains Paste Value

Hi,

I'm trying to write some code where it'll search each cell within a specified range and for each cell that contains =MIK it'll copy and paste each cell as a value. I've come up with the following but I think the .contains part isn't a valid command. Can anyone help? Thanks.

Option Explicit

Dim c as Range

Sheets("Trading Summary").Select

For Each c In Range("F36:M53")
If c.Contains = "=MIK" = True Then c.Copy c.PasteSpecial

Next c

RE: If Cell Contains Paste Value

Hi Mark

I've found a way which may help you continue.

See the code below. What it does is...
If a cell in the range F6:M53 starts with =MIK then the cell is copied and pasted as a value into the A column.
(Change A in the code to another location if you want)

Sub TestCopy()
Dim c As Range
Dim n As Integer 'counts the number of MIK cells copied
n = 0
Sheets("Trading Summary").Select
For Each c In Range("F6:M53")
If Left(c.Formula, 4) = "=MIK" Then
n = n + 1
c.Copy
Range("A" & n).PasteSpecial Paste:=xlPasteValues
End If
Next c
End Sub

Hope it helps.

Note =MIK has to be at the start of the cell. Is that ok or must it be found anywhere within the cell?


Regards
Doug
Best STL

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Copying Values Without Formulas in Excel 2010

If you want to copy the contents of a cell but don't want to copy the formula with it then use the following simple method:

Press Ctrl+C to copy the values in the cell. On the Home tab, click Paste and then click Paste Values.

View all Excel hints and tips


Server loaded in 0.05 secs.