Solved

conditional copy from column to another

Posted on 2014-02-21
5
292 Views
Last Modified: 2014-02-26
I have multiple Excel worksheets in a workbook in which I would like to, for each worksheet, inspect column C for the presence of only a hyphen "-".

  If there is only a hyphen present in the cell in Column C, then I want to copy what is in that same row in Column D into Column C.

  So, if row 10 of Column C has only a hyphen, then copy the contents of D10 into C10 and continue wherever there is only a hyphen in a cell in Column C.
0
Comment
Question by:vbaabv
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Harry Lee
ID: 39878541
Well, you can do it by VBA.

This will do it for one sheet.

Sub CheckColumnC()
Dim I As Long, WS As Worksheet
Set WS = ActiveSheet

For I = 1 To WS.Cells(Rows.Count, 3).End(xlUp).Row
    If WS.Cells(I, 3) = "-" Then
        WS.Cells(I, 3) = WS.Cells(I, 4)
    Else
        WS.Cells(I, 3) = WS.Cells(I, 3)
    End If
Next
End Sub

Open in new window

0
 
LVL 12

Accepted Solution

by:
Harry Lee earned 500 total points
ID: 39878550
This should takes care of all the worksheets in the workbook.

Sub CheckColumnCAllSheet()
Dim I As Long, WS As Worksheet
Set WB = ActiveWorkbook
For Each WS In Worksheets
    For I = 1 To WS.Cells(Rows.Count, 3).End(xlUp).Row
        If WS.Cells(I, 3) = "-" Then
            WS.Cells(I, 3) = WS.Cells(I, 4)
        Else
            WS.Cells(I, 3) = WS.Cells(I, 3)
        End If
    Next
Next
End Sub

Open in new window

0
 

Author Comment

by:vbaabv
ID: 39890617
Hi Harry Lee,

   Thank you very much ! This works very well. Sorry for the delay in getting  back to you.
0
 

Author Closing Comment

by:vbaabv
ID: 39890618
Nice job. Thank you very much.
0
 
LVL 12

Expert Comment

by:Harry Lee
ID: 39890713
That's great! Glad I can help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question