Table Placement with VBA

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
946
Office Version
  1. 2016
Platform
  1. Windows
Hello All.
I have the code below, which places the table on A1:M.
I'm having troubles placeing the table on A3:M. when I change the code of $A$1 : M, to $A$3:M. excel places the table on A1:M with crazy headers...basically if is not working.
So how do I get the table on A3:M, so I have 2 rows above that are blank?
Thanks for the help

VBA Code:
LastRow = Range("A:A").Cells.Find("*", _
        SearchOrder:=xlByRows, searchdirection:=xlPrevious).Row
'        MsgBox "The Last Non-Blank Row Is " & LastRow



'Adding Table
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:M" & LastRow), , xlYes).Name = _
"Table6"
Range("Table6[#All]").Select
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
It works for me as written, when you change A1 to A3. Are Rows 1 & 2 empty before the code is run.
 
Upvote 0
It works for me as written, when you change A1 to A3. Are Rows 1 & 2 empty before the code is run.
Yes because the report out starts as a blank sheet, and then data with headers is paste into cell A1, then report is run, beguining with A1
 
Upvote 0
I don't see your sheet. I took a sheet populated with fictitious data in the range of A1:P41. Your code created a table at A3:M41, with the fictitious data.
 
Upvote 0
I don't see your sheet. I took a sheet populated with fictitious data in the range of A1:P41. Your code created a table at A3:M41, with the fictitious data.
Capture.PNG


Thats what it is doing when I use A3
 
Upvote 0
How about a before picture of the same sheet... It appears as if it is doing what your code says. What is your expected result.
 
Upvote 0
I just took the easy way out and inserted two rows on top, now it works...
VBA Code:
'Shift Two Rows Down
Rows("1:2").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
 
Upvote 0
I am glad you got it squared away.
 
Upvote 0

Forum statistics

Threads
1,214,541
Messages
6,120,110
Members
448,945
Latest member
Vmanchoppy

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