Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Referencing a Column with a Variable name

I have a variable (Columnname) that finds a column where a Cell in a
row equals a value on another page.(A user inserts a date on the first
page and it matches a value in a row on another page and this variable
is set to that column) The problem I am having now is using it to set
other cells.

Normally to set a cell on this page I would use
worksheetname.Range("B4").Value = something

But since the column is not going to be equal to "B" every time I need
to be able to call that variable Columnname so something like
worksheetname.Range.("Columnname" + 3).value = somthing

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Referencing a Column with a Variable name

How about:

worksheetname.cells(4,columnname).value = something

(Don't you have to include the row, too?)


newguy wrote:

I have a variable (Columnname) that finds a column where a Cell in a
row equals a value on another page.(A user inserts a date on the first
page and it matches a value in a row on another page and this variable
is set to that column) The problem I am having now is using it to set
other cells.

Normally to set a cell on this page I would use
worksheetname.Range("B4").Value = something

But since the column is not going to be equal to "B" every time I need
to be able to call that variable Columnname so something like
worksheetname.Range.("Columnname" + 3).value = somthing


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Referencing a Column with a Variable name

You can do what Dave has suggested if ColumnName variable is an integer and
holds 1 for A and 2 for column B and so on.
On the other hand if ColumnName is a string variable holding "A","B" etc
then you can use a variation of what you have suggested

worksheetname.Range(ColumnName & 4).Value = something

Note that Worksheet name will have to be the programmatic name or else you
will need to use Worksheets(worksheetname).Range....

Alok

"newguy" wrote:

I have a variable (Columnname) that finds a column where a Cell in a
row equals a value on another page.(A user inserts a date on the first
page and it matches a value in a row on another page and this variable
is set to that column) The problem I am having now is using it to set
other cells.

Normally to set a cell on this page I would use
worksheetname.Range("B4").Value = something

But since the column is not going to be equal to "B" every time I need
to be able to call that variable Columnname so something like
worksheetname.Range.("Columnname" + 3).value = somthing


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Referencing a Column with a Variable name

This is not working for me it is giving me a user defined error. I
have tried both what you have suggested as well as Dave. Since it is
the last worksheet in the workbook I have also tried.
Worksheet(worksheets.count).Range(Columname & 4.Value = something

And it still isnt working for me.


Thanks for your help



Alok wrote:
You can do what Dave has suggested if ColumnName variable is an integer and
holds 1 for A and 2 for column B and so on.
On the other hand if ColumnName is a string variable holding "A","B" etc
then you can use a variation of what you have suggested

worksheetname.Range(ColumnName & 4).Value = something

Note that Worksheet name will have to be the programmatic name or else you
will need to use Worksheets(worksheetname).Range....

Alok

"newguy" wrote:

I have a variable (Columnname) that finds a column where a Cell in a
row equals a value on another page.(A user inserts a date on the first
page and it matches a value in a row on another page and this variable
is set to that column) The problem I am having now is using it to set
other cells.

Normally to set a cell on this page I would use
worksheetname.Range("B4").Value = something

But since the column is not going to be equal to "B" every time I need
to be able to call that variable Columnname so something like
worksheetname.Range.("Columnname" + 3).value = somthing



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Referencing a Column with a Variable name

Hi
Can you post the complete code from where the variable is declared to where
you get the error.
Alok

"newguy" wrote:

This is not working for me it is giving me a user defined error. I
have tried both what you have suggested as well as Dave. Since it is
the last worksheet in the workbook I have also tried.
Worksheet(worksheets.count).Range(Columname & 4.Value = something

And it still isnt working for me.


Thanks for your help



Alok wrote:
You can do what Dave has suggested if ColumnName variable is an integer and
holds 1 for A and 2 for column B and so on.
On the other hand if ColumnName is a string variable holding "A","B" etc
then you can use a variation of what you have suggested

worksheetname.Range(ColumnName & 4).Value = something

Note that Worksheet name will have to be the programmatic name or else you
will need to use Worksheets(worksheetname).Range....

Alok

"newguy" wrote:

I have a variable (Columnname) that finds a column where a Cell in a
row equals a value on another page.(A user inserts a date on the first
page and it matches a value in a row on another page and this variable
is set to that column) The problem I am having now is using it to set
other cells.

Normally to set a cell on this page I would use
worksheetname.Range("B4").Value = something

But since the column is not going to be equal to "B" every time I need
to be able to call that variable Columnname so something like
worksheetname.Range.("Columnname" + 3).value = somthing






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Referencing a Column with a Variable name

It's better to copy|paste your code directly from the VBE.

Is this an error in your message or an error in your code:

Worksheet(worksheets.count).Range(Columname & 4).Value = something
(note the additional close paren before the .Value)

And note that this style:
worksheetname.cells(4,columnname).value = something
will work if columnname is a number or a letter
(as long as it is valid (1:255, or A:IV))


newguy wrote:

This is not working for me it is giving me a user defined error. I
have tried both what you have suggested as well as Dave. Since it is
the last worksheet in the workbook I have also tried.
Worksheet(worksheets.count).Range(Columname & 4.Value = something

And it still isnt working for me.

Thanks for your help

Alok wrote:
You can do what Dave has suggested if ColumnName variable is an integer and
holds 1 for A and 2 for column B and so on.
On the other hand if ColumnName is a string variable holding "A","B" etc
then you can use a variation of what you have suggested

worksheetname.Range(ColumnName & 4).Value = something

Note that Worksheet name will have to be the programmatic name or else you
will need to use Worksheets(worksheetname).Range....

Alok

"newguy" wrote:

I have a variable (Columnname) that finds a column where a Cell in a
row equals a value on another page.(A user inserts a date on the first
page and it matches a value in a row on another page and this variable
is set to that column) The problem I am having now is using it to set
other cells.

Normally to set a cell on this page I would use
worksheetname.Range("B4").Value = something

But since the column is not going to be equal to "B" every time I need
to be able to call that variable Columnname so something like
worksheetname.Range.("Columnname" + 3).value = somthing



--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable cell referencing Paul Excel Worksheet Functions 1 February 16th 08 10:55 PM
Referencing tab based on Variable Chad Excel Worksheet Functions 2 June 8th 07 03:48 PM
Help with referencing variable range Cutter[_18_] Excel Programming 4 November 6th 05 12:38 AM
referencing worksheet as a variable crew3407 Excel Programming 3 April 28th 04 08:48 PM
Referencing variable Lee Excel Programming 1 December 4th 03 04:07 PM


All times are GMT +1. The time now is 06:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"