Dim & Copy & Paste

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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,
With both Dim statements I get the following error:

"Compile Error: Duplicate declaration in current scope"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top