name variable with 3 first characters of active cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello

another (I am sure) banal problem I am not able to cope with.

I need to name a variable named after 3 first characters of active cell.

I tried
dim var
var = left(activecell.value, 3)

i tried also
dim var, var1
var = activecell.value
var1 = left(var, 3)
as suggested in one of the threads

but I always get an error on this line of code

active cell contains text

any help appreciated

thanks in advance
 
Sorry,

I have tried the following code

Sub test()
Dim var, var1
var = ActiveCell.Value
var1 = Left(var, 3)
Debug.Print var1
End Sub

and it worked fine on my machine (Excel 2000). There should not be a
problem with your code but I guess that doesn't help you.
 
I have created this:

Public Sub threeChars()
Dim strValue As String
'
strValue = ActiveCell.Text
strValue = strValue & "___"
' 3 extra characters so next statement will not gif an error
strValue = Left(strValue, 3)

MsgBox strValue
End Sub

Check your regional settings you might need:

Public Sub threeChars()
Dim strValue As String
'
strValue = ActiveCell.Text
strValue = strValue & "___"
' 3 extra characters so next statement will not gif an error
strValue = Left(strValue; 3)

MsgBox strValue
End Sub


Hoop This Helps

Executor
 
Hi Shark,

your variable assignments work for me.

What error are you getting?

What is the code which produces the error?
 
I always get word keft highlighted (and it does not start with capital letter
as it should) and message error is
- compile error: wrong number of argumewnts or invalid property assignment

I am confused
 
In the VBE, go to Tools=>References and see if you have a reference marked
as MISSING. If you find one, you need to eliminate it as a reference or fix
it.

In the meantime, instead of Left, use VBA.Left
 
That sounds like you have greated a variable, function or sub named LEFT.
You need to give this a new name. It may not be that easy to fix. You can
try exiting Excel and reopening. If that doesn't help, export all your code
modules and delete them in the workbook, then save the workbook. Then
import the code again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top