VBA End Row

SandMan86

New Member
Joined
Feb 13, 2014
Messages
4
All,

I know there are several help topics for VBA end row -- but, I'm still relatively new to VBA, and I'm not sure if I can insert one of them into the macro that I've recorded to automate one of my daily reports.

I generate a report each day that summarizes all of the data M-T-D. Instead of adding each successive day, I run it fresh each day to ensure that everything gets exported from our billing/invoicing system. That being said, I take the data and format it as a pivot table because the end user prefers to see it that way. So, when I record the macro to create the pivot table, it records it with absolute reference. Here's the code that it's using for that:

ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$K$830"), , xlYes).Name = _
"Table1"

Does anyone know if there is a way I can edit this to select all contigious rows with data as opposed to a defined range of cells?

Thanks in advance!
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You can use something like this to determine the last row.

Define a variable a tthe top of your code.
Rich (BB code):
dim lstrow as long

Then this will work out the last row of used data based on column A
Rich (BB code):
lstrow = activesheet.Cells(Rows.Count, "A").End(xlUp).Row


Then when you are setting the range for the pivot the variable is called. notice how it needs to be outside the " with an & to link
Rich (BB code):
Rich (BB code):
Rich (BB code):
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$K" & lstrow), , xlYes).Name = "Table1"


Hope this helps. I haven't tested so make sure you check it but any questions let me know.

Cheers

soggy
 
Upvote 0
Maybe you can adapt something like this into you code.

Code:
Option Explicit

Sub AllMyRows()
  Dim Rng As Range
  Set Rng = Range("A1", Range("A1").End(xlDown))
  Rng.Select
End Sub

Regards,
Howard
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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