I've got an Excel file that should have the text 'UNK' as the first 3 letters开发者_如何学Python of cell A10 (I don't care what comes after the UNK). If it does NOT match this text, I need to insert a blank line at the top of the Excel file. For some reason my code is not evaluating correctly and I'm not sure why. I'm using:
If Left(A10, 3) <> "UNK" Then
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End If
As you might be able to tell, I'm a novice with this type of code. Any help is much appreciated.
What about this? It loops until either A10 is blank or it finds UNK.
Do While Range("A10") <> ""
If Left(Range("A10"), 3) <> "UNK" Then
Rows("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Else
Exit Do
End If
Loop
I would change this to:
If Left(Range("A10"), 3) <> "UIC" Then
Range("A1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End If
精彩评论