Return value of most recent non-blank value in column

artz

Well-known Member
Joined
Aug 11, 2002
Messages
830
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have a column of data values separated by rows with blanks. How can I return value of the most recent non-blank value in a column row using VBA for use in a VBA sub?

Thanks,

Art
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi, artz,

I'm new here, hope this can help:

Code:
Option Explicit


Sub SkipBlank()


Dim to_use As String
Dim cell, data, target As Range


Set target = Range("a1", "a10")
Set data = Range("b1")


For Each cell In target


    If cell.Value <> "" Then
        to_use = cell.Value
        data.Value = to_use
        Set data = data.Offset(1, 0)
    End If
    
    
Next


End Sub

With what you said, this macro do exactly what you want.

:)
 
Upvote 0
Hi EuEdu,

Thanks for your prompt reply. So, I am starting with the following VBA code:
Code:
Sub Compare()
Dim i As Long
For i = 2 To 302
    If Range("B" & i).Value >= Range("F" & i).Value Then
         Range("O" & i) = Range("F" & i).Value
    End If
Next
End Sub

This does not work because the value in column B does not reflect the previous and latest value in column F. Do you see a way to combine your code with my code to accomplish what I was asking for?

Any help is appreciated. :-)

-Art
 
Upvote 0
Hi EuEdu,

Thanks for your code. It does work as advertised. :-)

Thanks again,

-Art
 
Upvote 0
Hi EuEdu,

Everybody is busy these days, no problem. I do appreciate the help!

Thanks,

-Art
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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