+ Reply to Thread
Results 1 to 2 of 2

Macro to selectively copy cells from excel.

Hybrid View

  1. #1
    Registered User
    Join Date
    11-27-2011
    Location
    Chennai, India
    MS-Off Ver
    Excel 2007
    Posts
    1

    Macro to selectively copy cells from excel.

    Hi,
    I am a novice in excel macro programming, and new to this forum. I need a help in developing a Macro - VB script for the following scenario.

    I have 3 columns, Column A, Column B and Column C.
    I want macro to check contents of Column B and wherever there is a blank, macro should copy correspoding content in Column A to Column C. Column C shouldn't have any blanks.

    Ex:
    Column A Column B Column C
    abc 123 efg
    cde 234 ijk
    efg
    ghi 456
    ijk
    klm 678

    Any help will be much appreciated. Thanks in advance.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Macro to selectively copy cells from excel.

    Hi Venkat89, I don't know if this is the fix but it is a start. Try
    Option Explicit
    
    Sub CopyFromBlanks()
        Dim oCell As Range
        Dim Ws1 As Worksheet
        
        Set Ws1 = Worksheets("Sheet1")
        For Each oCell In Ws1.Range(Ws1.Cells(1, 1), Ws1.Cells(Rows.Count, 1).End(xlUp))
            If oCell.Offset(0, 1).Value = "" Then oCell.Offset(0, 2).Value = oCell.Value
        Next oCell
    End Sub
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1