Solved

conditional copy from column to another

Posted on 2014-02-21
5
287 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Nice job. Thank you very much.
0
 
LVL 12

Expert Comment

by:Harry Lee
Comment Utility
That's great! Glad I can help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
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 demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now