ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with syntax in line of code (https://www.excelbanter.com/excel-programming/414809-help-syntax-line-code.html)

pignick

Help with syntax in line of code
 
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.
--
pignick

Bob Phillips

Help with syntax in line of code
 
UserGroup = Selection.Value

--
HTH

Bob

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

"pignick" wrote in message
...
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.
--
pignick




Gary''s Student

Help with syntax in line of code
 
UserGroup = Selection.Value
--
Gary''s Student - gsnu200796

pignick

Help with syntax in line of code
 
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?

--
pignick


"Bob Phillips" wrote:

UserGroup = Selection.Value

--
HTH

Bob

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

"pignick" wrote in message
...
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.
--
pignick





pignick

Help with syntax in line of code
 
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.
--
pignick


"pignick" wrote:

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.
--
pignick



All times are GMT +1. The time now is 10:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com