Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Can't Copy and Paste or Paste Special between Excel Workbooks | Excel Discussion (Misc queries) | |||
Copy, paste without file name referenced after paste | Excel Discussion (Misc queries) | |||
help w/ generic copy & paste/paste special routine | Excel Programming | |||
Excel cut/Paste Problem: Year changes after data is copy and paste | Excel Discussion (Misc queries) | |||
Copy and Paste macro needs to paste to a changing cell reference | Excel Programming |