Visual Basic App to Select Last Row

mattpfc

Active Member
Joined
Nov 21, 2002
Messages
299
Hi all,

I need to be able to select the first blank row in my spreadsheet, however I am doing this from a VB app, and not within Excel itself.

The VB abb creates an excel workbook using this code

Code:
Public Function Create_Workbook()

    ' Start Excel and get Application object.
        Set oXL = CreateObject("Excel.Application")
        oXL.Visible = True

   ' Get a new workbook.
        Set oWB = oXL.Workbooks.Add
        Set oSheet = oWB.ActiveSheet

End Function

However in a number of different functions I wish to write to the next available row, how can I find this. I have tried this code, but with no luck

Code:
Dim oRng As Excel.Range

oRng = oSheet.Cells(Range("a65536").End(xlUp).Row + 1, 1).Select

Thanks in advance
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
What does "with no luck" mean? You get a compile error? Run time error? Something else?

In any case, one thing stands out. Range, like Cells, is a property of a worksheet object. However, you are using it without any qualification.
 
Upvote 0

Forum statistics

Threads
1,223,319
Messages
6,171,427
Members
452,402
Latest member
siduslevis

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