Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

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

ResolvedVersion 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:

Hide columns in an Excel 2010 Worksheet

If you don’t want part of the Excel worksheet to be visible or when you don’t want certain data to appear in print outs, then a simple solution is to temporarily hide a column or multiple columns.

Hiding a single column:

1)Right click on the column header of the column you want to hide (this is the grey bar along the top edge of the worksheet)
2)Choose Hide from the menu
3)This column will now be hidden from view

Hide more than one column:

1)In the column header drag select to highlight the columns you want hidden
2)Right click and choose Hide from the menu

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.