Function to Get Last Used Row From Excel Worksheet
By Scott Gall
Function which will get the last used cell in an excel worksheet.
This function will return the last used cell from a given worksheet.
Public Function GetLastCell(ws As Worksheet) As Range
Dim rngResult As Range
On Error GoTo ErrHandler
Set rngResult = ws.UsedRange.SpecialCells(xlCellTypeLastCell)
ExitPoint:
On Error GoTo 0
Exit Function
ErrHandler:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure GetLastRow"
GoTo ExitPoint
Resume
Resume Next
End Function
Function to Get Last Used Row From Excel Worksheet (448 Views)
Generating Random number between specified range The Fuction generates a Random Number between the Specified range The below Function takes two values as Arguements and provides the Random number between the Range specified . the function goes like this. . . < script type = "text / javascript" language = "javascript"> f unction RandomNumber(x, y) { var range = y - x + 1; alert( ' Random number : ' + ( Math .floor( Math .random() * range) + x) + ' between ' + x + ' and ' + y); } < / script > Calling the aove function iam passing the Values as 0 and 10 so the range would be between 0 - 10 < input type = "button" name = "btnTest
b / w ToInt16, ToInt32 and ToInt64 It depends on the number range you are dealing with. Refer to the below grid. Operation Output Range Output Type Bytes per Element Output Class int8 -128 to int64 Hi, Detail on Data type are as follows : Type Description Minimum Maximum Bits bool Boolean flag false true 1 byte integer data in .net languages and they differ in the range int16 can store the integers between -32, 768 to 32
setting a variable range in vba please can you help me to create a range, using vba - the top left hand corner of the range is fixed, but the number of columns and rows of the range change depending on the data. Specifically, I cant figure the coding to create a range which starts at cell c6, and is x colums wide and y rows high, where x is the number in cell a1, and y is the number contained in cell a2. Any advice much appreciated! I do this all the time using the Offset method of the range. Here's some sample code: Sub RangeTest() Dim rng As Range Dim rowOffset As Long Dim columnOffset As Long ' grab offets
have a spreadsheet that contains 3 types of columns, Item, description and finally dates in chronological order. Each row contains and item number, description and a qty under each date (either 0 or higher etc. And each row would hold information such as Item#, Description, 0, 0, 4000, 0, 700, etc. The goal would be to return the Item#, Description and the column header (date) for the value 4000 (in work in terms of selecting each row or selecting a range of values to be evaluated. I hope this clears any Name = OUTPUT_WORKSHEET Set shOutput = Worksheets(OUTPUT_WORKSHEET) 'Create header row shOutput.Range( "A1" ).Value = "Item" shOutput.Range( "B1" ).Value = "Descr" shOutput.Range( "C1" ).Value = "Date" Else 'Clear output worksheet except for header shOutput.UsedRange.Clear shOutput.Range( "A1" ).Value = "Item" shOutput.Range( "B1" ).Value = "Descr" shOutput.Range
is an example. Each record starts with PO Line Item Number and ends with Tax Article Number. Considering conversion, sometimes there is a blank row or a I am looking for is in the PO Line Item Number in the 3rd column: 44.00 and 4th column: 16.98 and in Brief Description row 2nd column: 04 / 03 / 2011 - ITEM1 - INDUSTRIAL 3 For and 'end' in order to correctly extract cells from each range and then do it until it reaches the end of perhaps you could share. Thank you Example: PO Line Item Number 000001 Quantity 44.00 Unit Price 16.98 Item Total Code Taxation country Code Tax Rate Tax Amount Buyers Part Number Sellers Part Number Billing Period Start Date Billing Period End Date Delivery Order Number Airway Bill Number Brief Description 04 / 03 / 2011 - ITEM1 - INDUSTRIAL 3 Invoice Item
a given worksheet. Public Function GetLastCell(ws As Worksheet) As Range Dim rngResult As Range On Error GoTo ErrHandler Set rngResult = ws.UsedRange.SpecialCells(xlCellTypeLastCell On Error GoTo 0 Exit Function ErrHandler: MsgBox "Error " & Err. Number & " (" & Err. Description & ") in procedure GetLastRow" GoTo ExitPoint Resume Resume Next End Function Views ) View Scott Gall's FAQs Create New Account keywords: Range, Number, Description, Dim, Error, GoTo, Exit, Resume description: Function which will get the last used cell in an
Runtime Error '9': Subscript out of range. Hi, I have a script below where all I changed was : from: varValue2 = Split(Range("D" & lngRow), " ")(0) to: varValue2 = Split(Range("E" & lngRow), " ")(0) And this results in an error message Runtime Error '9': Subscript out of range. Any suggestions why the change (from column D to column To Cells(Rows.Count, "A").End(xlUp).Row If Trim(Range("A" & lngRow)) Like "PO Line Item Number*" Then varValue1 = Split(Range("C" & lngRow), " ")(0) varValue2 = Split(Range("E" & lngRow), " ")(0) ElseIf Trim Range("A" & lngRow)) Like "Brief Description*" Then lngTRow = lngTRow + 1 wsTarget.Range("A" & lngTRow) = Range("B
and need to cross reference eligibility dates against the wireless number. Our customers are not consistant in how they enter their wireless number, so I expanded each to fit the 5 most common customer entries, so the wireless number of (111-222-3333) would be in each spreadsheet (AT E). Column F holds the date / vaue of when the number will be eligible for an upgrade. I need to use an EXACT match, otherwise it could return a number that is not in our list. With 30, 000 rows of wireless numbers and 18 columns of information (wireless number, electronic serial number, contract start date, SIM number etc), stacking the information end to end as a single Sheet 1 as the front page to enter the wireless number and the rest of the sheets as data tabs (AT SPrint / Nextel (sheet 4) etc). Sheet 1 Titles - (A1) Wireless Number (B1) Eligibility Date (C1) Customer Name (D1) Vendor Name Results