+ Reply to Thread
Results 1 to 6 of 6

Copy value from column "X" paste into Column "Y" - visible cells

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Copy value from column "X" paste into Column "Y" - visible cells

    Hi,

    I tried to write a macro, it works fine but as I am learning I wondered if there were any pitfalls or perhaps something I have missed.
    Your guidance will be greatly appreciated.

    Thanks

    Sub Copy_Value()
    '
    '
    '
    
    '
        Rows("1:1").Select
        Selection.Find(What:="CASH_CODE", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        ActiveSheet.ListObjects("tblBoNYData").Range.AutoFilter Field:=12, Criteria1 _
            :="BATRANS"
            
        Do
        ActiveCell.Offset(1, 0).Select
        Loop Until Rows(ActiveCell.Row).Hidden = False
        
        Selection.Copy
     
        Rows("1:1").Select
        Selection.Find(What:="ELE_CODE4", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
            
        Do
        ActiveCell.Offset(1, 0).Select
        Loop Until Rows(ActiveCell.Row).Hidden = False
            
        ActiveSheet.Paste
        Range(Selection, Selection.End(xlDown)).Select
        Selection.SpecialCells(xlCellTypeVisible).Select
        Application.CutCopyMode = False
        Selection.FillDown
        
        Rows("1:1").Select
        Selection.Find(What:="CASH_CODE", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        
        Do
        ActiveCell.Offset(1, 0).Select
        Loop Until Rows(ActiveCell.Row).Hidden = False
        
       ActiveCell.FormulaR1C1 = "-"
        Range(Selection, Selection.End(xlDown)).Select
        Selection.SpecialCells(xlCellTypeVisible).Select
        Selection.FillDown
        
        ActiveSheet.ListObjects("tblBoNYData").Range.AutoFilter Field:=12
            
    End Sub

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Copy value from column "X" paste into Column "Y" - visible cells

    What is the purpose of your code?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Copy value from column "X" paste into Column "Y" - visible cells

    Hi,

    If column heading is "CASH_CODE" filter for "BATRANS"
    Copy cells containing "BATRANS" from column "CASH_CODE" to column "ELE_CODE4" then replace "BATRANS" in column "CASH_CODE" with "-"

    Hope this makes sense

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Copy value from column "X" paste into Column "Y" - visible cells

    Is the code giving you any errors currently?

  5. #5
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Copy value from column "X" paste into Column "Y" - visible cells

    Hi Arlette,

    Yes it doesn't work if there is only 1 row containing BATRANS, I am concerned I may have missed something as I am a novice.

    Ta
    Last edited by kaseyleigh; 02-22-2012 at 05:42 AM.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Copy value from column "X" paste into Column "Y" - visible cells

    You can start getting rid of the select & activate statements. It makes the code longer and takes time to run as well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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