VBA: If satisfying condition on partial match

Adar123

Board Regular
Joined
Apr 1, 2018
Messages
83
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
I am using the following code to copy data from one cell to another. The challenge I am having is with with the definition of the if condition as a partial match: The cells in column A contain information in the following format: RANDOM_TEXT_25DP.

I need to copy data whenever cell A contains _25DP at the end. How do I do that?

Current code

VBA Code:
Sub MoveData()

Dim k As Integer, kMove As Integer
Dim Kcolumn As Long, Ccolumn As Long
Dim refCell As Range, outputCell As Range

Kcolumn = 7                 ' destination
Ccolumn = 6                  ' reference

For k = 2 To 5000
    If Cells(k, 1) = "_25DP" Then
        kMove = k -1
        Set refCell = Cells(k, Ccolumn)
        Set outputCell = Cells(kMove, Kcolumn)
        outputCell.Value = refCell.Value
    End If
Next k

End Sub
 
You're welcome. Have you tried it on the large data yet to see how it goes for speed?
I could add some explanations to the code if that is required.
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I tested on a few thousands lines of data, works quite quickly. I din't measure second of that particular part of the code but it is not noticeable.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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