lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I wanted to do the code below without using for-loop, but it did not work. Is it possible to do it without For loop?
Thank you so much.
Code:
Sub myleft()
    'For x = 1 To 10
    'Cells(x, 2) = Left(Cells(x, 1), 2)
    'Next x
    '''''''
    Range("b1:b10") = Left(Range("a1:a10"), 2)
End Sub
 
Last edited:

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
try this:

Code:
Sub foo()
Range("B1:B10").Formula2R1C1 = "=LEFT(RC[-1],2)"
End Sub
 
Upvote 0
Another way:
Code:
Sub WithoutLoop()
  With Range("A1:A10")
    .Offset(0, 1).Value = Evaluate(Replace("if(@="""","""",trim(replace(trim(@),3,len(@),"""")))", "@", .Address))
  End With

End Sub
 
Upvote 0
Another way (this puts the values in the cells directly rather than formulas referring back to the previous column)...
Code:
[table="width: 500"]
[tr]
	[td]Sub GetLeftTwoCharacters()
  Range("A1:A10").TextToColumns Range("B1"), xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(2, 9))
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Maybe...

Code:
Sub myleft()
    With Range("B1:B10")
        .Formula = "=Left(A1,2)"
        .Value = .Value
    End With
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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