{"id":188,"date":"2019-08-14T21:43:21","date_gmt":"2019-08-14T21:43:21","guid":{"rendered":"https:\/\/keithratner.live\/optionexplicit\/?p=188"},"modified":"2019-08-14T22:28:48","modified_gmt":"2019-08-14T22:28:48","slug":"getlastusedcolumnnumberinworksheet","status":"publish","type":"post","link":"https:\/\/keithratner.live\/optionexplicit\/getlastusedcolumnnumberinworksheet\/","title":{"rendered":"GetLastUsedColumnNumberInWorksheet"},"content":{"rendered":"<pre>Function GetLastUsedColumnNumberInWorksheet( _\r\n    ws As Worksheet _\r\n) As Long\r\n    Dim _\r\n        rng As Range, _\r\n        rngResults As Range\r\n    Set rng = _\r\n        ws.Cells\r\n    Set rngResults = _\r\n        rng.Find( _\r\n            what:=\"*\", _\r\n            After:=rng.Cells(1), _\r\n            Lookat:=xlPart, _\r\n            LookIn:=xlFormulas, _\r\n            SearchOrder:=xlByColumns, _\r\n            SearchDirection:=xlPrevious, _\r\n            MatchCase:=False _\r\n        )\r\n    If _\r\n        rngResults Is Nothing _\r\n        Then\r\n        GetLastUsedColumnNumberInWorksheet = _\r\n            -1\r\n    Else\r\n        GetLastUsedColumnNumberInWorksheet = _\r\n            rngResults.Column\r\n    End If\r\n    Exit Function\r\nErrorHandler:\r\n    GetLastUsedColumnNumberInWorksheet = _\r\n        -1\r\nEnd Function<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Function GetLastUsedColumnNumberInWorksheet( _ ws As Worksheet _ ) As Long Dim _ rng As Range, _ rngResults As Range Set rng = _ ws.Cells Set rngResults = _ rng.Find( _ what:=&#8221;*&#8221;, _ After:=rng.Cells(1), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByColumns, _ SearchDirection:=xlPrevious, _ MatchCase:=False _ ) If _ rngResults Is Nothing _ Then GetLastUsedColumnNumberInWorksheet = _ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[114],"tags":[121,154],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-snippet","tag-excel","tag-worksheet"],"krwpengineoptions-featuredonwpengineblog":"","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pgsIIA-32","jetpack-related-posts":[{"id":186,"url":"https:\/\/keithratner.live\/optionexplicit\/getlastusedrownumberinworksheet\/","url_meta":{"origin":188,"position":0},"title":"GetLastUsedRowNumberInWorksheet","author":"Keith","date":"August 14, 2019","format":false,"excerpt":"Function GetLastUsedRowNumberInWorksheet( _ ws As Worksheet _ ) As Long Dim _ rng As Range, _ rngResults As Range Set rng = _ ws.Cells Set rngResults = _ rng.Find( _ what:=\"*\", _ After:=rng.Cells(1), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False _ ) If _ rngResults Is Nothing\u2026","rel":"","context":"In &quot;Snippet&quot;","block_context":{"text":"Snippet","link":"https:\/\/keithratner.live\/optionexplicit\/category\/snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":60,"url":"https:\/\/keithratner.live\/optionexplicit\/hashiddencolumns\/","url_meta":{"origin":188,"position":1},"title":"HasHiddenColumns","author":"Keith","date":"April 4, 2019","format":false,"excerpt":"Public Function HasHiddenColumns( _ rng As Range _ ) As Boolean Dim _ rngColumn As Range HasHiddenColumns = False For Each rngColumn In rng.Columns If rngColumn.Hidden Then HasHiddenColumns = True End If Next rngColumn End Function Usage: Dim _ wsSource As Worksheet, _ rngSource as Range Set wsSource = ThisWorkbook.Sheets(\"Sheet1\")\u2026","rel":"","context":"In &quot;Snippet&quot;","block_context":{"text":"Snippet","link":"https:\/\/keithratner.live\/optionexplicit\/category\/snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":177,"url":"https:\/\/keithratner.live\/optionexplicit\/workbooksheetexists\/","url_meta":{"origin":188,"position":2},"title":"WorkbookSheetExists","author":"Keith","date":"July 10, 2019","format":false,"excerpt":"Public Function WorkbookSheetExists( _ wb As Workbook, _ strSheetName As String _ ) As Boolean Dim ws As Worksheet WorkbookSheetExists = False For Each ws In wb.Sheets If ws.Name = strSheetName Then WorkbookSheetExists = True End If Next ws End Function","rel":"","context":"In &quot;Snippet&quot;","block_context":{"text":"Snippet","link":"https:\/\/keithratner.live\/optionexplicit\/category\/snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":214,"url":"https:\/\/keithratner.live\/optionexplicit\/deleteinitialcolumnsfromworksheet\/","url_meta":{"origin":188,"position":3},"title":"DeleteInitialColumnsFromWorksheet","author":"Keith","date":"September 11, 2019","format":false,"excerpt":"Note: This function depends on ReturnName Sub DeleteInitialColumnsFromWorksheet( _ ws As Worksheet, _ NumberOfColumns As Integer _ ) With ws .Columns( _ ReturnName( _ 1 _ ) & _ \":\" & _ ReturnName( _ NumberOfColumns _ ) _ ).Delete _ Shift:=xlToLeft End With End Sub","rel":"","context":"In &quot;Snippet&quot;","block_context":{"text":"Snippet","link":"https:\/\/keithratner.live\/optionexplicit\/category\/snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":182,"url":"https:\/\/keithratner.live\/optionexplicit\/deleteallslicersfromworkbook\/","url_meta":{"origin":188,"position":4},"title":"DeleteAllSlicersFromWorkbook","author":"Keith","date":"August 12, 2019","format":false,"excerpt":"Public Function DeleteAllSlicersFromWorkbook( _ wb As Workbook _ ) Dim _ ws As Worksheet, _ shp As Shape For Each ws In wb.Sheets For Each shp In ws.Shapes If shp.Type = msoSlicer Then shp.Delete Next shp Next ws End Function","rel":"","context":"In &quot;Snippet&quot;","block_context":{"text":"Snippet","link":"https:\/\/keithratner.live\/optionexplicit\/category\/snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":190,"url":"https:\/\/keithratner.live\/optionexplicit\/deletebottomrowsfromworksheet\/","url_meta":{"origin":188,"position":5},"title":"DeleteBottomRowsFromWorksheet","author":"Keith","date":"August 14, 2019","format":false,"excerpt":"Note: This method depends on GetLastUsedRowNumberInWorksheet Sub DeleteBottomRowsFromWorksheet( _ ws As Worksheet _ ) Dim _ strStartingEmptyRow As String, _ rngStartingRow As Range, _ rngEmptyRows As Range, _ lngLastRow As Long lngLastRow = _ GetLastUsedRowNumberInWorksheet( _ ws _ ) If lngLastRow = _ -1 Then Exit Sub End If strStartingEmptyRow\u2026","rel":"","context":"In &quot;Snippet&quot;","block_context":{"text":"Snippet","link":"https:\/\/keithratner.live\/optionexplicit\/category\/snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":2,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/posts\/188\/revisions"}],"predecessor-version":[{"id":194,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/posts\/188\/revisions\/194"}],"wp:attachment":[{"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/media?parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/categories?post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/tags?post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}