PC Review


Reply
Thread Tools Rate Thread

Dim & Copy & Paste

 
 
=?Utf-8?B?Sm9zaCBPLg==?=
Guest
Posts: n/a
 
      12th Jul 2007
I have the below macro to find cells in column 14 and paste them to column
"A", same row, if there is data in that cell.

I need to be able to do the same thing for another column in the same
worksheet (ie - find values in 16th column and paste to same row column "I"),
but I get an error if I try to use similar code (just changing the column
index and destination column).

Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, 14).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 14) <> "" Then
Application.CutCopyMode = False
Cells(i, 14).Copy
Range("a" & Cells(i, 14).Row).Select
ActiveSheet.Paste
End If
Next

 
Reply With Quote
 
 
 
 
=?Utf-8?B?V2lnaQ==?=
Guest
Posts: n/a
 
      13th Jul 2007
Hellowa Josh

Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, 14).End(xlUp).Row
For i = 2 To lastrow
If Cells(i, 14) <> "" Then Cells(i, 14).Copy Range("a" & i)
Next

'and

Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, 16).End(xlUp).Row
For i = 2 To lastrow
If Cells(i, 16) <> "" Then Cells(i, 16).Copy Range("I" & i)
Next



--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"Josh O." wrote:

> I have the below macro to find cells in column 14 and paste them to column
> "A", same row, if there is data in that cell.
>
> I need to be able to do the same thing for another column in the same
> worksheet (ie - find values in 16th column and paste to same row column "I"),
> but I get an error if I try to use similar code (just changing the column
> index and destination column).
>
> Dim lastrow As Long, i As Long
> lastrow = Cells(Rows.Count, 14).End(xlUp).Row
> For i = lastrow To 2 Step -1
> If Cells(i, 14) <> "" Then
> Application.CutCopyMode = False
> Cells(i, 14).Copy
> Range("a" & Cells(i, 14).Row).Select
> ActiveSheet.Paste
> End If
> Next
>

 
Reply With Quote
 
=?Utf-8?B?Sm9zaCBPLg==?=
Guest
Posts: n/a
 
      13th Jul 2007
Wigi,
With both Dim statements I get the following error:

"Compile Error: Duplicate declaration in current scope"

"Wigi" wrote:

> Hellowa Josh
>
> Dim lastrow As Long, i As Long
> lastrow = Cells(Rows.Count, 14).End(xlUp).Row
> For i = 2 To lastrow
> If Cells(i, 14) <> "" Then Cells(i, 14).Copy Range("a" & i)
> Next
>
> 'and
>
> Dim lastrow As Long, i As Long
> lastrow = Cells(Rows.Count, 16).End(xlUp).Row
> For i = 2 To lastrow
> If Cells(i, 16) <> "" Then Cells(i, 16).Copy Range("I" & i)
> Next
>
>
>
> --
> Wigi
> http://www.wimgielis.be = Excel/VBA, soccer and music
>
>
> "Josh O." wrote:
>
> > I have the below macro to find cells in column 14 and paste them to column
> > "A", same row, if there is data in that cell.
> >
> > I need to be able to do the same thing for another column in the same
> > worksheet (ie - find values in 16th column and paste to same row column "I"),
> > but I get an error if I try to use similar code (just changing the column
> > index and destination column).
> >
> > Dim lastrow As Long, i As Long
> > lastrow = Cells(Rows.Count, 14).End(xlUp).Row
> > For i = lastrow To 2 Step -1
> > If Cells(i, 14) <> "" Then
> > Application.CutCopyMode = False
> > Cells(i, 14).Copy
> > Range("a" & Cells(i, 14).Row).Select
> > ActiveSheet.Paste
> > End If
> > Next
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I get copy/paste to copy/paste text and not the whole page =?Utf-8?B?Q2Fyb2wgSi4=?= Microsoft Word Document Management 1 6th May 2005 09:03 PM
Copy and Paste macro needs to paste to a changing cell reference =?Utf-8?B?bG91bG91?= Microsoft Excel Programming 0 24th Feb 2005 10:29 AM
Copy & Paste Object without using the Excel Copy Paste functions =?Utf-8?B?R2Fueg==?= Microsoft Excel New Users 0 10th Mar 2004 07:06 AM
Copy & Paste Object without using the Excel Copy Paste functions =?Utf-8?B?R2Fueg==?= Microsoft Excel Misc 0 10th Mar 2004 07:06 AM
Re: Copy/Paste in Excel prints highlighted cells and does not paste Dave Peterson Microsoft Excel Misc 0 30th Jul 2003 11:08 PM


Features
 

Advertising
 

Newsgroups
 


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