Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VBA to select characters from a cell range

Status
Not open for further replies.

mjmacarty

MIS
Mar 29, 2003
8
US
I am trying to assign the first three characters of cell range to a variable. I would then like to copy and paste these characters into another cell range. Can't seem to do it! I have tried using both string and characters variable declarations. I am a novice though can someone help?
 
I don't really understand what you mean by "cell range" but will assume that you require the first 3 characters of a field on a form, if this is the case than you can use the Left() function. This is used to select a number of characters from the lefthand side of a field.
Field is called Identity and has 2134445
Left([Identity],3) would produce 213
Right([Identity],3) would produce 445
 
Use the .name property of your range object to return the name then use the left() function to return the first three characters.
 
OK. Here is an example of the code I am using incorporating your code.
Dim lftchar As String
lftchar = Application.Workbooks(1).Worksheets(1).Range("a1:a4").Left([identity], 3)

I want to paste the first three characters from all cells in column a to column b and add a 3 digit random number to generate a randomized username.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top