OzGrid

How to copy cell if cell contains the value to the previous column but the same row

< Back to Search results

 Category: [Excel]  Demo Available 

How to copy cell if cell contains the value to the previous column but the same row

 

Requirement:

 

The user wants to find value contains in column B and if found copy them to column A in the same row. For example if the value in B4 contains my search value i.e "*CASH*" then copy that to A4 and the same goes to the rest. The user has a macro given in the attached .xls but if run this in sheet1 the result will be like as given in "macro test result" sheet without giving the one required like as shown in "result needed" sheet. can anyone help on this code?

 

https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/148209-copy-cell-if-containing-the-value-to-the-previous-column-but-the-same-row

 

Solution:

 

Code:
Sub Test()
    Dim bottomB As Integer
    bottomB = Sheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Row
     
    Dim c As Range
    For Each c In Sheets("sheet1").Range("B1:B" & bottomB)
        If c.Value Like "*CASH*" Then
            c.Copy Worksheets("Sheet1").Range("A" & c.Row)
        End If
    Next c
End Sub

 

Obtained from the OzGrid Help Forum.

Solution provided by Carim.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to find and replace based on list entered by user input
How to create VBA code to increment number each time a copy is printed
How to count cells in a dynamic range matching two criteria given in table headers
How to copy master sheet as values and automatically set new name

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)