Solved

conditional copy from column to another

Posted on 2014-02-21
5
296 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

615 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