Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Dim & Copy & Paste

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Dim & Copy & Paste

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Dim & Copy & Paste

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
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
Can't Copy and Paste or Paste Special between Excel Workbooks wllee Excel Discussion (Misc queries) 5 April 29th 23 03:43 AM
Copy, paste without file name referenced after paste AusTexRich Excel Discussion (Misc queries) 6 September 23rd 08 02:57 AM
help w/ generic copy & paste/paste special routine DavidH[_2_] Excel Programming 5 January 23rd 06 03:58 AM
Excel cut/Paste Problem: Year changes after data is copy and paste Asif Excel Discussion (Misc queries) 2 December 9th 05 05:16 PM
Copy and Paste macro needs to paste to a changing cell reference loulou Excel Programming 0 February 24th 05 10:29 AM


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

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

About Us

"It's about Microsoft Excel"