How to count and change cell characters with Long type parameters?

F_Ribeiro

New Member
Joined
Jan 14, 2021
Messages
32
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello everybody!


I would like to go through the rows of a column using numeric variables to reference the parameters. But in doing so I can't use text functions, like Len () to count the characters in a cell, Left () and Right (), among others. How do I resolve this dilemma, is there a function that counts characters of any type?

Thank you for your attention, I'm waiting.


VBA Code:
Sub F_Ribeiro()
Dim W As Worksheet
Dim xRow As Long
Dim lastRow As Long

Set W = Sheets("Sheet1")

lastRow = W.Range("A" & Rows.Count).End(xlUp).Row

For xRow = 2 To lastRow

If Len(W.Range("A" & xRow)) > 4 Then
    W.Range("A" & xRow).Value = Right(W.Range("A" & xRow), 3)
End If
Next

End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
What's the problem with your code?
When I run the code, an error appears mentioning incompatible types. I believe it is because I used text functions, but the variables I created to go through the loop are numeric. It could be something else, of course.
 
Upvote 0
Hello everybody! Again, he he.

Well, for some reason the code worked, I don't understand why it failed before. So that matter is resolved. I thank you for your attention and hope that nobody goes through this kind of problem, it is horrible not knowing how to solve something apparently simple.

To the next.
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,726
Members
449,093
Latest member
Mnur

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