1

So I'm 90% of the way into creating my first big macro project. Thanks for all your help so far everyone! I've come up against an issue however - which I think should be the last issue I should face before putting the macro into use.

I've written a macro which copies the data presented in a master spreadsheet, creates a new workbook in the target location, then creates a table using the information provided.

What I want to do is use CurrentRegion to allow the data to alter month-to-month. I think the code should go something like this

`GeneratePivotTables Macro

'Converts information stored on sheet "Data" to a table

Dim TABLE As Range

Set TABLE = Sheets("Data").A1.CurrentRegion

Sheets("Data").Listobjects.Add(x1SrcRange, Range("TABLE"), ,1Xyes).Name="Data"

I know this as presented is incorrect, but I'd like some help just parsing this correctly! My aim is to then be able to use the table "Data" to create pivot tables.

3
  • 1
    what is the A1 doing after Sheets("data")? did you mean sheets("data").Range("A1")? Commented May 22, 2015 at 15:28
  • Yep, that fixed that bit of the code! it's saying the next bit Sheets("Data").Listobjects.Add(x1SrcRange, Range("TABLE"), ,1Xyes).Name="Data" is invalid syntax - which i know, but i want to know how to correct it! Commented May 22, 2015 at 15:31
  • replace the range("Table") with just TABLE, thats the first thing noticed so far Commented May 22, 2015 at 15:37

2 Answers 2

7

The following code converts the CurrentRegion around cell A1 into a table. See if you can modify it for your needs.

Sub ConvertRangetoTable()
    Dim rngTable As Range

    Set rngTable = Sheets("Data").Range("A1").CurrentRegion

    Sheets("Data").ListObjects.Add(xlSrcRange, rngTable, , xlYes).Name = "All_Data"
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I think this is pretty much exactly what I need!
0

This seems to be sufficient

Sub M_snb()
    Sheet1.ListObjects.Add(1, [A1].CurrentRegion, , 1).Name = "snb_001"
End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.