+ Reply to Thread
Results 1 to 9 of 9

Simple Excel macro

Hybrid View

  1. #1
    Justin Philips
    Guest

    Re: Simple Excel macro

    as far as I know you cannot copy multiple cells to the clipboard. A
    better solution would be to copy the cells you choose to a new column.


    Sub Copy()
    Dim x As Single, y As Single

    x = 1
    y = 1

    Do While Range("G" & x).Value <> ""
    If Range("G" & x).Value = "1" Then
    Range("C" & x).Select
    Range("C" & x).Copy
    Range("H" & y).PasteSpecial
    y = y + 1
    End If
    x = x + 1
    Loop
    End Sub

    You can replace the Range("H") for wherever you would like the data to
    be sent to...I dont know if this helps but it does work!

    -Justin


  2. #2
    Registered User
    Join Date
    03-16-2006
    Posts
    2
    Tom I appreciate the help but Justin was right, although that selects only the individual fields in Column C, when I copy and paste it copys the entire column.

    Justin that macro you posted does pretty much what I wanted, I can just copy column H (which I changed to B) But I have another question. Can I change:

    Do While Range("G" & x).Value <> ""
    If Range("G" & x).Value = "1"

    to use the column I currently have selected instead of manually having to change G to a different column? there's about 50 different columns I have to run this macro for.

  3. #3
    Justin Philips
    Guest

    Re: Simple Excel macro

    try this:

    Sub Copy()
    Dim x, y, c As Single

    x = 1
    y = 1
    c = ActiveCell.Column

    Do While Cells(x, c).Value <> ""
    If Cells(x, c).Value = "1" Then
    Range("C" & x).Select
    Range("C" & x).Copy
    Range("B" & y).PasteSpecial
    y = y + 1
    End If
    x = x + 1
    Loop
    End Sub

    so will you be running this macro fifty times?
    you could have it run through all fifty columns and paste everything
    into a new sheet. I dont know what your needs are.
    HTH
    -Justin


  4. #4
    Tom Ogilvy
    Guest

    Re: Simple Excel macro

    What I provided does what you ask.

    If you wanted to replace the 1's in column G with the corresponding value
    in column C, then that certainly isn't what you stated.

    --
    Regards,
    Tom Ogilvy


    "madbunny" <madbunny.24s7fy_1142544604.325@excelforum-nospam.com> wrote in
    message news:madbunny.24s7fy_1142544604.325@excelforum-nospam.com...
    >
    > Tom I appreciate the help but Justin was right, although that selects
    > only the individual fields in Column C, when I copy and paste it copys
    > the entire column.
    >
    > Justin that macro you posted does pretty much what I wanted, I can just
    > copy column H (which I changed to B) But I have another question. Can I
    > change:
    >
    > Do While Range("G" & x).Value <> ""
    > If Range("G" & x).Value = "1"
    >
    > to use the column I currently have selected instead of manually having
    > to change G to a different column? there's about 50 different columns I
    > have to run this macro for.
    >
    >
    > --
    > madbunny
    > ------------------------------------------------------------------------
    > madbunny's Profile:

    http://www.excelforum.com/member.php...o&userid=32541
    > View this thread: http://www.excelforum.com/showthread...hreadid=523253
    >




  5. #5
    Justin Philips
    Guest

    Re: Simple Excel macro

    Yes Tom's does work. Don't forget to add:

    Dim cell as Range

    You can decide which serves your purposes better.

    -Justin


  6. #6
    Tom Ogilvy
    Guest

    Re: Simple Excel macro

    Thanks for the note. To continue the helping:

    Dim x, y, c As Single

    x is variant
    y is variant
    c is single

    is that what you intended?

    Most would do

    Dim x as Long, y as Long, c as Long

    --
    Regards,
    Tom Ogilvy

    "Justin Philips" <philipsj@gmail.com> wrote in message
    news:1142603946.573476.259680@z34g2000cwc.googlegroups.com...
    > Yes Tom's does work. Don't forget to add:
    >
    > Dim cell as Range
    >
    > You can decide which serves your purposes better.
    >
    > -Justin
    >




  7. #7
    Justin Philips
    Guest

    Re: Simple Excel macro

    oh yeah...thanks!


+ 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