VBA Macro Create a Table from Cell Address

VbaAz

New Member
Joined
Jun 13, 2015
Messages
4
Hello I Am Looking For VBA macro to create a table. The cell Address's though for the range of the table is bassed on the text in the cells. For Example A2 = "First Word" and D21 = "Second Word". I need a macro that will look up the cell address of each of those words and then create a table using that as the range. Ive looked all over and cannot find something with exactly what I need. I really appreciate any information.

Thank you!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
This is a total shot in the dark... as I am not sure I understand all that you want.. but anyway, here goes...
If you sheet looks this way, with RangeNames set for Cell A2 and D21 of First_Word and Second_Word, respectively (RangeNames CANNOT contain spaces)...


Excel 2012
ABCDE
1
2First Word
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21Second Word
22
23
Sheet1


Run this Macro Foo

Code:
Sub Foo()
    ActiveSheet.ListObjects.Add(xlSrcRange, _
    Range(Range("First_Word").Offset(-1), Range("Second_Word").Offset(-1)), , xlNo).Name = _
        "Table1"
    Set LO = Sheets("Sheet1").ListObjects("Table1")
    LO.DataBodyRange.Select
    Selection.ListObject.ListRows(1).Delete
    Range("A1:D21").Select
End Sub

Afterwards you will get: (Which is a Table: Table1)


Excel 2012
ABCD
1Column1Column2Column3Column4
2First Word
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21Second Word
Sheet1
 
Upvote 0
Jim - This is very specific, but I would like to build on it for the general case.

I have a list anywhere in the worksheet that reads:

California
San Diego
Los Angeles
San Francisco
Fresno
Carlsbad

The macro recorder is cell specific, so I can't figure out what edits to make.

Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$I$12:$I$14"), , xlYes).Name = _
"Table2"
Range("Table2[[#All],[Alaska]]").Select

Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,555
Messages
6,125,490
Members
449,234
Latest member
slzaleski

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