When I attempt to copy/paste the following text from 3 cells from an excel file:
Total - Net Revenue
Total - Standard Revenue
Total - Realization Percentage
Into the following code:
Sub CopyColumnsToNewSheet2()
Dim i, LastCol
LastCol = Range("IV1").End(xlToLeft).Column
For i = 1 To LastCol
If UCase(Cells(1, i).Value) = "Total - Net Revenue
" Then
Cells(1, i).EntireColumn.Copy Destination:= _
Sheets("Sheet2").Range("E1")
End If
If UCase(Cells(1, i).Value) = "Total - Standard Revenue
" Then
Cells(1, i).EntireColumn.Copy Destination:= _
Sheets("Sheet2").Range("F1")
End If
If UCase(Cells(1, i).Value) = "Total - Realization Percentage
" Then
Cells(1, i).EntireColumn.Copy Destination:= _
Sheets("Sheet2").Range("G1")
End If
Next
End Sub
- The text in red is causing a syntax error.
- There appears to be a "return" entered in the code when I copy to VBA.
- If I manually type the text into the VB, the text is not found.
Does anyone have any ideas on what is going on with my data. NOTE: the data was imported into excel from a CSV file. As an FYI, if I change the text to Header1, Header2 and Header3 and update the VB, the macro works (see attached screenshot oPasteSyntaxError.jpgf both sets of code).
Thank you.
Bookmarks