Home > OS >  Error in vba code that takes first 4 characters from one column to another
Error in vba code that takes first 4 characters from one column to another

Time:11-03

Hello i am trying to take the first 4 characters from the B column (starting from B2) and copy them to I column (starting from I2) What is wrong in this code? It shows up as error "1004" But im not sure what is wrong in this code.

Dim Cell As Range
For Each Cell In Range("B2:B100").Cells
    If Cell.Value = "" Then
        Cell.Value = Left(Cell.Offset(0, -7).Value, 4)
    End If
Next
End Sub

Maybe you can find a mistake in the code that might indicate an error, thanks!

CodePudding user response:

You've got your columns mixed up. Loop column B, and write into column I (which is an offset of 7, not -7).

If Cell.Value <> "" Then
   Cell.Offset(,7).Value = Left(Cell.Value, 4)
End If
  • Related