1

I have some code that opens an excel spreadsheet and gets the last empty row in that column. The problem I am having is that I have two tables created in my excel spreadsheet. I want to be able to only select the range of B7:B94 for column B as I have data that represents another table starting at B:101 Here is my code so far...

Const xlUp = -4162 Set xlApp = CreateObject("Excel.Application") With xlApp .Visible = False Set xlWB = .Workbooks.Open("M:\Shared Documents\Job Cost Analysis\Hi-Tech BPO\Logs\" & currentMonth & "-Summary Hi Tech BPO.xlsx", , False) Set ws = .Worksheets(sheetName) Dim LR '''''''''''Here is where I want to select the range of B7:B94'''''''''''''' LR = .Range("B" & .Rows.count).End(xlUp).Row .Range("B" & LR + 1).Value = RIGHT(client_id,LEN(client_id)-7) End With xlApp.DisplayAlerts = False xlWB.SaveAs ("M:\Shared Documents\Job Cost Analysis\Hi-Tech BPO\Logs\" & currentMonth & "-Summary Hi Tech BPO.xlsx") xlWB.Close xlApp.Quit 
2
  • Are those actual ListObject (aka structured) tables or just blocks of data? Commented May 9, 2016 at 17:42
  • and LR = .Range("B101").End(xlUp).Row does not work? Commented May 9, 2016 at 17:44

2 Answers 2

1

For unstructured blocks of data,

LR = .Range("B100").End(xlUp).Row 

For true ListObject (aka structured) tables,

LR = .Range("B100").End(xlUp).End(xlUp).Row 

The latter assumes that the table is not 'full'. A check to ensure LR is not 7 should be made.

Sign up to request clarification or add additional context in comments.

Comments

1

How about

.Range("B7").End(xlDown).Offset(1,0).Row 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.