ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to assign contents of a cell to a macro variable (https://www.excelbanter.com/excel-programming/395932-how-assign-contents-cell-macro-variable.html)

DavidH[_2_]

how to assign contents of a cell to a macro variable
 
Hi,

I'm trying to set the contents of cell A6 in the "General Documentation"
worksheet of the active workbook to a variable. First I test for the General
Documentation worksheet, and that part of my code works. Here's the next part:

Dim CellDesc As String
CellDesc = ActiveWorkbook.Sheets("General Documentation").Cells(a6).Value

I get error 1004, application defined or object defined error. Should I be
using something else besides string? Does it make a difference if the cell
value is a string or a number?

Thanks for the help!

David




Dave Peterson

how to assign contents of a cell to a macro variable
 
either:
CellDesc = ActiveWorkbook.Sheets("General Documentation").Cells("a6").Value
(Notice the "A6" change.)

or

CellDesc = ActiveWorkbook.Sheets("General Documentation").Cells(6,"A").Value



DavidH wrote:

Hi,

I'm trying to set the contents of cell A6 in the "General Documentation"
worksheet of the active workbook to a variable. First I test for the General
Documentation worksheet, and that part of my code works. Here's the next part:

Dim CellDesc As String
CellDesc = ActiveWorkbook.Sheets("General Documentation").Cells(a6).Value

I get error 1004, application defined or object defined error. Should I be
using something else besides string? Does it make a difference if the cell
value is a string or a number?

Thanks for the help!

David


--

Dave Peterson

Vergel Adriano

how to assign contents of a cell to a macro variable
 
David,

Try:

CellDesc = ActiveWorkbook.Sheets("General Documentation").Range("A6").Value

--
Hope that helps.

Vergel Adriano


"DavidH" wrote:

Hi,

I'm trying to set the contents of cell A6 in the "General Documentation"
worksheet of the active workbook to a variable. First I test for the General
Documentation worksheet, and that part of my code works. Here's the next part:

Dim CellDesc As String
CellDesc = ActiveWorkbook.Sheets("General Documentation").Cells(a6).Value

I get error 1004, application defined or object defined error. Should I be
using something else besides string? Does it make a difference if the cell
value is a string or a number?

Thanks for the help!

David




DavidH[_2_]

how to assign contents of a cell to a macro variable
 
Thanks Vergel, it worked perfectly!




All times are GMT +1. The time now is 10:56 PM.

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