Populate a table Column with a cell value VBA

ManUBlueJay

Active Member
Joined
Aug 30, 2012
Messages
326
Office Version
  1. 365
Platform
  1. Windows
I am looking to pupulate an ebtire table Column with the value from on cell in VBA
I would have thought this should work.
Any help would be appriciated

VBA Code:
ActiveSheet.ListObjects("MyTable").ListColumns(1).DataBodyRange = Range(MyCell).value
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I am looking to pupulate an ebtire table Column with the value from on cell in VBA
I would have thought this should work.
Any help would be appriciated

VBA Code:
ActiveSheet.ListObjects("MyTable").ListColumns(1).DataBodyRange = Range(MyCell).value
It works for me.

What does Range(MyCell) refer to?
 
Upvote 0
How exactly in "MyCell" defined and set?

What you posted would work if "MyCell" is a String value returning a cell address.
If "MyCell" is actually a range object, then you would just use:
VBA Code:
ActiveSheet.ListObjects("MyTable").ListColumns(1).DataBodyRange = MyCell.Value

Also, the fact that "value" is lower case concerns me. It should be upper case.
Maybe that is just a typo on your part. If it is not, it means that you probably created a variable, procedure, or function named "value" (a big no-no, you should never used reserved words as the names of variables, procedures, or functions), and that could cause errors.
 
Upvote 0
Please show us part of the code where you declare and set that variable.
 
Upvote 0
There is nothing to show. There is a named range in excell called "MyCell"
I have used Range(MyCell) many times successfully
 
Upvote 0
There is nothing to show. There is a named range in excell called "MyCell"
I have used Range(MyCell) many times successfully
Not like that you have.

VBA Code:
Range(MyCell)
is looking for a VBA variable named "MyCell"

If you want to reference the literal range named "MyCell", you need to enclose it in double-quotes, i.e.
VBA Code:
Range("MyCell")

Rule of thumb: Anything enclosed in double-quotes is treated a literal string. If it is not enclosed in double-quotes, it is looking for a reference to a variable, function, or procedure.
Since you are looking for a range literally named "MyCell", you need to use double-quotes around it.
 
Upvote 0
Solution
You are welcome.

The double-quotes are very important and make all the difference. I went back and edited the previous post to explain why they are needed in a little more detail.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,118
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top