Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Simple Excel macro


If anyone can help me with this problem I'd appreciate it.
I'm trying to make what I'd assume is a simple excel macro but I canno
find any useful FAQs or website with actual useful help on making exce
macros.

Basically I want to select a column, let's call it column G, and I wan
the macro to check every field in that column from say 5 to 100 and i
there's a 1 in that field, then get the information in column C in th
same row, and put it into the windows clipboard so I can paste i
later.

I'm using Selection.Cells(x,1).value in a loop and incrementing x t
find the value in the selected column, but how do I then select colum
C in the same row if it's a 1? Also I'm unsure how to add thi
information to windows clipboard. I want to be able to ctrl-V once I'v
run the macro and simple paste the list of information that wa
retrieved.

If anyone can help me with this or simply point me to a useful onlin
resource I'd appreciate it

--
madbunn
-----------------------------------------------------------------------
madbunny's Profile: http://www.excelforum.com/member.php...fo&userid=3254
View this thread: http://www.excelforum.com/showthread.php?threadid=52325

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Simple Excel macro

sub addtoclipboard()
Dim rng as Range
for each cell in Range("G5:G100")
if cell.value = 1 then
if rng is nothing then
set rng = cell
else
set rng = union(rng,cell)
end if
end if
Next
if not rng is nothing then
set rng = Intersect(rng.entireRow,Columns(3))
rng.select
rng.copy
else
msgbox "Nothing to copy"
end if
End Sub

Just remember that there are many actions that will clear the clipboard

--
Regards,
Tom Ogilvy


"madbunny" wrote:


If anyone can help me with this problem I'd appreciate it.
I'm trying to make what I'd assume is a simple excel macro but I cannot
find any useful FAQs or website with actual useful help on making excel
macros.

Basically I want to select a column, let's call it column G, and I want
the macro to check every field in that column from say 5 to 100 and if
there's a 1 in that field, then get the information in column C in the
same row, and put it into the windows clipboard so I can paste it
later.

I'm using Selection.Cells(x,1).value in a loop and incrementing x to
find the value in the selected column, but how do I then select column
C in the same row if it's a 1? Also I'm unsure how to add this
information to windows clipboard. I want to be able to ctrl-V once I've
run the macro and simple paste the list of information that was
retrieved.

If anyone can help me with this or simply point me to a useful online
resource I'd appreciate it.


--
madbunny
------------------------------------------------------------------------
madbunny's Profile: http://www.excelforum.com/member.php...o&userid=32541
View this thread: http://www.excelforum.com/showthread...hreadid=523253


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Simple Excel macro


Tom I appreciate the help but Justin was right, although that select
only the individual fields in Column C, when I copy and paste it copy
the entire column.

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

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

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

--
madbunn
-----------------------------------------------------------------------
madbunny's Profile: http://www.excelforum.com/member.php...fo&userid=3254
View this thread: http://www.excelforum.com/showthread.php?threadid=52325

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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" wrote in
message ...

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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default 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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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" wrote in message
oups.com...
Yes Tom's does work. Don't forget to add:

Dim cell as Range

You can decide which serves your purposes better.

-Justin



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Simple Excel macro

oh yeah...thanks!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Excel Macro TimWillDoIt New Users to Excel 5 April 25th 07 06:17 PM
simple excel macro Q excelbeginner Excel Programming 2 March 8th 06 08:06 PM
New Excel user needs help with simple Macro... Rahim Kassam New Users to Excel 1 January 24th 05 02:10 PM
simple excel vba macro Andrew Slentz Excel Programming 4 May 21st 04 08:57 AM
Simple Excel Macro - Please Help Curious[_3_] Excel Programming 7 October 23rd 03 04:26 PM


All times are GMT +1. The time now is 09:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"