Left Len function with VBA

Dokat

Active Member
Joined
Jan 19, 2015
Messages
304
Office Version
  1. 365
Hi,

I have a table where i would like to delete last 6 character in each row on column C.

I am using below code to delete last 6 characters basically left Len function. When I ran it doesn't give me an error however it doesn't do anything. Can nayone help me with this issue? Thanks

VBA Code:
Sub CopyPaste()

Application.ScreenUpdating = False

    Dim Wb As Workbook
    Dim Ws As Worksheet
    Set Wb = ActiveWorkbook
    Set Ws = Sheets("Summary by L5")
    Wb.Activate
    Ws.Select

With Ws
    For i = 21 To lastrow
        .Cells(i, 3) = Left(.Cells(i, 3).Value, Len(.Cells(i, 3).Value) - 6)
    Next i
End With
    
Application.ScreenUpdating = True
 
In a column to the right put this formula:

=Len(C21) and copies it down.
Check with autofilter which cells have less than 6 characters.


---------------------
The error is because when performing the subtraction the result is negative and the Left function does not accept negatives.


Exmaple
.Cells(i, 3) = Left(amor, Len(amor) - 6)
.Cells(i, 3) = Left(amor, 4 - 6)
.Cells(i, 3) = Left(amor, -2) 'error
I think what's happening is there are 2 blank rows on the bottom of the rows that's what causing the issue
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,215,077
Messages
6,122,995
Members
449,094
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top