Ravindra Bagale · Excelसर्व coursesया course चे lessonsशोधाEnglish

Excel · मराठी आवृत्ती

12.11 Last row आणि last column

रवींद्र बागले यांच्या course वर आधारित · सहज मराठीत explanation

या page मध्ये

रोज data वाढत असेल तर शेवटची row 11 किंवा 5000 hard-code करू नका. ws आधी target worksheetला Set करा.

Dim lastRow As Long, lastCol As Long
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row          ' last filled row in column A
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column   ' last filled column in row 1

Column Aच्या तळापासून वर गेल्यावर शेवटची populated cell मिळते. Column A प्रत्येक recordमध्ये भरलेला असावा. LastCol हे row 1मधले शेवटचे header शोधतं; dataमधले दूरचे stray values नाही.

Edge cases

4,800 records आणि header row1 असेल तर lastRow4801 आणि ws.Range("A2:A" & lastRow) = A2:A4801.

Practice

Last row, last column आणि ws.Range(ws.Cells(1,1),ws.Cells(lastRow,lastCol)).Address MsgBoxमध्ये दाखवा. Header-only sheet आणि मध्ये blank key असलेली copyही तपासा.