Help with syntax in line of code

P

pignick

I am trying to write a macro that will insert one of a number of possible
logos depending on the "user group" name, which appears in a cell after data
is downloaded to the worksheet.

The following code stops at the line UserGroup=Selection.String -
(highlighted yellow in the debug) - there is obviously something wrong with
the syntax here and I have tried a number of things without success. I know
it works in other situations where I use Dim CritValue as Integer and then do
IF, THEN statements to act on different numbers of CritValue, but as this is
text it doesn't work the same way. Can anyone help please?

Dim UserGroup As String
UserGroup = " "
ActiveSheet.Unprotect
ActiveSheet.Range("AJ1").Select
UserGroup = Selection.String
If UserGroup = "Garth Partnership" Then
(the subsequent instructions to insert the logo work fine from a macro
linked to an object but I want to automate this without the need for clicking
on an object).

Thanks in anticipation.
 
B

Bob Phillips

UserGroup = Selection.Value

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
P

pignick

Thanks, but I should have explained that I had initially tried that and it
doesn't work with the text string , which puzzled me as it does work in other
situations using a number, so must be something wrong somewhere.

Any other suggestions?
 
P

pignick

Sorted it - the UserGroup name appeared to be referenced to cell AJ1 but that
cell was also merged with the next two cells - as soon as I unmerged them
(which did not affect the display of the name as it simply spread across the
adjacent cells anyway), the Selection.Value code worked fine and the rest of
the macro was implemented. Thanks for your help - I'm slowly learning how to
use VBA but it's frustrating when you come up against simple problems like
this.
 

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

Top