Copy and paste data based on text in cell next to it [VBA]

anarchyflag

New Member
Joined
Nov 2, 2018
Messages
15
I have some code that I want to check every cell in in the range “A3:AAA3” for a specific text. If the cell contains that text, I want it to copy the text in the cell on the right, to two rows above (see below for illustration):

1587114055216.png


The copied text will be a date. This is what I have so far:

VBA Code:
Sub Weeks_commencing()

Dim c As Range
For Each c In ThisWorkbook.Worksheets("Sheet1").Range("A3:AAA3").Cells
    If c.Value Like "*TEXT*" Then
        c.Offset(ColumnOffset:=1).Copy Destination:=c.Offset(RowOffset:=-2)
    End If
Next c

End Sub

It’s not coming up with an error message, it’s just not doing anything. Have I missed something?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try :
VBA Code:
If UCase(c.Value) Like "*TEXT*" Then
 
Upvote 0
Try :
VBA Code:
If UCase(c.Value) Like "*TEXT*" Then


Hello - thanks for this. It wasn't that, because the "TEXT" thing was just an example, but it did make me realise that I had not formatted the text in the code the same way that it was written in the spreadsheet, which made it work!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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