{"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_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,4,3],"tags":[],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-code","category-distribution","category-vba"],"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;Code&quot;","block_context":{"text":"Code","link":"https:\/\/keithratner.live\/optionexplicit\/category\/code\/"},"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;Code&quot;","block_context":{"text":"Code","link":"https:\/\/keithratner.live\/optionexplicit\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":86,"url":"https:\/\/keithratner.live\/optionexplicit\/transferrangedataasarray\/","url_meta":{"origin":188,"position":2},"title":"TransferRangeDataAsArray","author":"Keith","date":"April 8, 2019","format":false,"excerpt":"Public Function TransferRangeDataAsArray( _ rngSource As Range, _ rngTarget As Range, _ Optional xlrvd As XlRangeValueDataType = xlRangeValueDefault _ ) As Range Set TransferRangeDataAsArray = _ rngTarget.Resize( _ rngSource.Rows.Count, _ rngSource.Columns.Count _ ) TransferRangeDataAsArray.Value( _ xlrvd _ ) = _ rngSource.Value( _ xlrvd _ ) End Function","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/keithratner.live\/optionexplicit\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":609,"url":"https:\/\/keithratner.live\/optionexplicit\/iscellhighlighted\/","url_meta":{"origin":188,"position":3},"title":"IsCellHighlighted","author":"Keith","date":"May 24, 2024","format":false,"excerpt":"Function IsCellHighlighted(cell As Range) As Boolean IsCellHighlighted = (cell.Interior.ColorIndex <> xlNone)End Function","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":134,"url":"https:\/\/keithratner.live\/optionexplicit\/trimrange\/","url_meta":{"origin":188,"position":4},"title":"TrimRange","author":"Keith","date":"April 24, 2019","format":false,"excerpt":"Public Function TrimRange( _ rngSource As Range, _ Optional TrimTop As Integer = 0, _ Optional TrimBottom As Integer = 0, _ Optional TrimLeft As Integer = 0, _ Optional TrimRight As Integer = 0 _ ) As Range Set TrimRange = _ rngSource.Offset( _ rowoffset:=TrimTop, _ columnoffset:=TrimLeft _ ).Resize(\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/keithratner.live\/optionexplicit\/category\/code\/"},"img":{"alt_text":"TrimRange","src":"https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/trimrange.png?fit=430%2C240&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":184,"url":"https:\/\/keithratner.live\/optionexplicit\/deleteallconnectionsfromworkbookoftype\/","url_meta":{"origin":188,"position":5},"title":"DeleteAllConnectionsFromWorkbookOfType","author":"Keith","date":"August 12, 2019","format":false,"excerpt":"Public Function DeleteAllConnectionsFromWorkbookOfType( _ wb As Workbook, _ xlconnType As XlConnectionType _ ) Dim _ wbcn As WorkbookConnection For Each wbcn In wb.Connections If wbcn.Type = xlconnType Then wbcn.Delete End If Next wbcn End Function","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/keithratner.live\/optionexplicit\/category\/code\/"},"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}]}}