Solved

conditional copy from column to another

Posted on 2014-02-21
5
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
: 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 create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

749 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