Retrieve column of last non-zero value in VBA

louiserace

New Member
Joined
Jun 24, 2015
Messages
15
I have a spreadsheet which is created using VBA and I want to retrieve the column of the last non zero value on row 1 (range(K1:T1)). This is so I can use the column later in the code.

I am using Excel 2016.

Any help would be appreciated.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Heres one way:

Code:
myCol = Application.Match(10 ^ 10, Sheets("Sheet1").Range("K1:T1"))
If Not IsError(myCol) Then myCol = myCol + 10

The sheet will need changing as appropriate. The myCol variable will be an integer representing the last column with a number in the range.
 
Upvote 0
Sorry just seen none zero. Maybe then:

Code:
myCol = Evaluate("=LOOKUP(2,1/((Sheet1!K1:T1<>0)*(ISNUMBER(Sheet1!K1:T1))),COLUMN(Sheet1!K1:T1))")
 
Upvote 0
Solution

Forum statistics

Threads
1,226,117
Messages
6,189,061
Members
453,524
Latest member
AshJames

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