Macro to find previous non blank cell

aa2000

Board Regular
Joined
Aug 3, 2011
Messages
87
Hi guys

I have a column of data where certain cells contain a value and other are blank, with a varying number of blank cells between each used cell.Example:

w
blank
blank
blank
x
y
blank
z

I am trying (with no luck) to write a macro that will move up from one of the blank cells and find and make bold the first used cell it finds, then stop

Can anyone help?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Well this macro will be called by another one which looks through the column to the left of this one. When that macro finds a specific value it looks to this column and if the cell has a value its made bold, if its blank it calls this macro. (Makes sense?)

So I'd like to get it to move up from any blank cell and find the previous cell in that column with a value and make that bold.
 
Upvote 0
Heres my code thus far and it works the every time i press f5, however it is not restricted to finding items in the one column and will make any used cell above the active cell bold. How can I modify it to restrict it one column?

Code:
Sub Up()
Dim FirstCol As Long
            
            FirstCol = Cells.Find("*", ActiveCell, xlValues, xlPart, xlByRows, xlPrevious, False, False, False).Activate
            ActiveCell.Font.Bold = True
            
                                       
End Sub

This macro is called by another macro shown below:

Code:
Sub Find()

Set Rng2 = Tabelle2.Range("D3:D65536")
Dim c As Object

For Each c In Rng2.Cells
    If c.Value = "FWB" Then
        If c.Offset(0, -3).Value = "*" Then c.Offset(0, -3).Font.Bold = True
        End If
        If c.Offset(0, -3).Value = "" Then Call Up
    If c.Value = "KL" Then
        If c.Offset(0, -3).Value = "*" Then c.Offset(0, -3).Font.Bold = True
        End If
        If c.Offset(0, -3).Value = "" Then Call Up
    If c.Value = "KF" Then
        If c.Offset(0, -3).Value = "*" Then c.Offset(0, -3).Font.Bold = True
        End If
        If c.Offset(0, -3).Value = "" Then Call Up
Next c

End Sub

Another problem I have is that there is nothing to stop the macro "Up" from continuously running after being called so it won't just make bold the first used cell but any above that as well. Anybody know how I can modify it to do that instead?

Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,799
Members
452,943
Latest member
Newbie4296

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