Consulting

Results 1 to 10 of 10

Thread: Finding a cell then copying data 2 cells right

  1. #1

    Finding a cell then copying data 2 cells right

    Hello all, thanks in advance for the help as I am baffled.

    This is what I need a macro to do:

    Begin at cell B1
    Look at the cell and if the cell value is "PROVIDER" jump over 2 cells to the right, copy that data, and paste it in Column A of another Worksheet. Then go back to Column B and continue down the list until it reaches the end of the data (note there are no spaces until the end so I'm trying to do it with a Do While Not IsEmpty(ActiveCell) code.)

    Thanks again
    Chip

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi there,

    This will copy from all cells in column B, and if the cell value matches "PROVIDER" exactly (all caps), it will copy it to the next available cell in column A on Sheet2:

    Sub CopyIt()
     Dim cl As Range
     With Worksheets("Sheet1")
     For Each cl In .Range("B1:B" & .Range("B65536").End(xlUp).Row)
         If cl.Value = "PROVIDER" Then
             cl.Copy Worksheets("Sheet2").Range("A65536").End(xlUp).Offset(1, 0)
         End If
     Next cl
     End with
     End Sub
    For reference, this: "B1:B" & .Range("B65536").End(xlUp).Row could easily be "B1:B25"

    Let me know if you need any modifications.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    Thanks for the help, but I'm looking more for code that will move the ActiveCell around.


    When the code sees PROVIDER in column B it should copy the cell in D of that row and paste it in the other sheet.

  4. #4
    VBAX Contributor Aaron Blood's Avatar
    Joined
    Sep 2004
    Location
    Palm Beach, Florida, USA
    Posts
    130
    Location
    If you're wiling to use my Find_Range function, you can do it in a single action.


    Sub Ex_12()
    x = "PROVIDER"
    Set Found_Range = Find_Range(x, Sheet1.Columns("B"), xlValues, xlPart).Offset(0, 2)
    Found_Range.Copy Range("Sheet2!A1")
    End Sub

    The code for the Find_Range function is available on my website.
    http://www.xl-logic.com/xl_files/vba...d_function.zip

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Sorry, Chipchuck, I missed the column D.

    For reference, the below code is adjusted to account for that.

    Sub CopyIt()
         Dim cl As Range
         With Worksheets("Sheet1")
         For Each cl In .Range("B1:B" & .Range("B65536").End(xlUp).Row)
             If cl.Value = "PROVIDER" Then
                 cl.offset(0,2).Copy Worksheets("Sheet2").Range("A65536").End(xlUp).Offset(1, 0)
             End If
         Next cl
         End with
         End Sub
    FYI, this will accomplish what you want without moving the activecell. We could modify it to use the activecell, but it is unnecessary to do so. Basically what this does is look at B1 and if it equals "PROVIDER" it will copy D1 to the next available cell on Sheet2 column A. Then it goes back to B2 and continues on.

    I haven't tried Aaron's (Open Source! ) solution, but am sure it will work also.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    VBAX Contributor Aaron Blood's Avatar
    Joined
    Sep 2004
    Location
    Palm Beach, Florida, USA
    Posts
    130
    Location
    Quote Originally Posted by kpuls
    I haven't tried Aaron's (Open Source! ) solution, but am sure it will work also.
    Alright... what's so funny about the open source comment?

  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    It's just the "new wave" kind of thing. Everything is going "open source" these days. I've just never seen anyone refer to their VBA stuff that way yet.

    I'm not questioning the accuracy of the statement at all, it's just that most VBA'ers that I've met so far still say that it "isn't password protected" or something.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  8. #8
    VBAX Contributor Aaron Blood's Avatar
    Joined
    Sep 2004
    Location
    Palm Beach, Florida, USA
    Posts
    130
    Location
    Quote Originally Posted by kpuls
    It's just the "new wave" kind of thing. Everything is going "open source" these days. I've just never seen anyone refer to their VBA stuff that way yet.

    I'm not questioning the accuracy of the statement at all, it's just that most VBA'ers that I've met so far still say that it "isn't password protected" or something.
    OIC, I'm not really in the programming world. Wasn't aware of the possible cheesiness factor... I'll avoid saying it in the future then.

  9. #9
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Aaron, that wasn't at all what I was getting at. It's less words... use it!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  10. #10
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location

    Talking

    ROFLMAO!!!

    You two are hilarious!

    Cheesiness factor .. .. .. 10!!! LOL!

Posting Permissions

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