sitzalke

New Member
Joined
May 13, 2019
Messages
11
Hi. I am beginner to excel vba. I would like to ask simple question that I've been stuck for few days.
So far, I have two columns, for example column L and M.
I have to loop all column L and find the blank cell. If there are a blank cell, then, it will copy next value in column M.
Roughly, the column is like this,
Column LColumn M
15
4

<tbody>
</tbody>

so supposedly second row of column L will be 4. The flow will be until end of the lastrow.
So far, my code is like this,
Code:
  Dim c As Range    Dim searchrange As Range
    Dim i As Long


    Set searchrange = Range("L2", Cells(Rows.Count, 1).End(xlUp))


    For i = searchrange.Cells.Count To 1 Step -1
        Set c = searchrange.Cells(i)
        If c.Value = "" Then
        'c.Value.Copy Range("M2")
       c.Value.Copy Destination:=Range("M")
        End If
    Next i

Thanks in advance
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
looks a little like an assignment. Is that ALL of the question ?
And what happens when M gets to zero, does it go into negative numbers ?
 
Upvote 0
Assuming no blanks in col M over the range of data in col L:
Code:
Sub Sitzalke()
Dim R As Range, Rblank As Range, c As Range
Set R = Range("L2", Cells(Rows.Count, "L").End(xlUp))
On Error Resume Next
Set Rblank = R.SpecialCells(xlCellTypeBlanks)
If Rblank Is Nothing Then
    MsgBox "No blank cells in col L)"
    Exit Sub
End If
Application.ScreenUpdating = False
For Each c In R.SpecialCells(xlCellTypeBlanks)
    c.Value = c.Offset(1, 1).Value
Next c
Application.ScreenUpdating = True
End Sub
 
Upvote 0
OR

Code:
Sub MM1()
Dim cell As Range
For Each cell In Range("L2", Cells(Rows.Count, 12).End(xlUp))
    If cell.Value = "" Then cell.Offset(, 1).Value = cell.Offset(-1, 1).Value - 1
    Next cell
End Sub
 
Upvote 0
Assuming no blanks in col M over the range of data in col L:
Code:
Sub Sitzalke()
Dim R As Range, Rblank As Range, c As Range
Set R = Range("L2", Cells(Rows.Count, "L").End(xlUp))
On Error Resume Next
Set Rblank = R.SpecialCells(xlCellTypeBlanks)
If Rblank Is Nothing Then
    MsgBox "No blank cells in col L)"
    Exit Sub
End If
Application.ScreenUpdating = False
For Each c In R.SpecialCells(xlCellTypeBlanks)
    c.Value = c.Offset(1, 1).Value
Next c
Application.ScreenUpdating = True
End Sub

Thanks this is working. A lot. May God Bless you for this kindness. Thanks again
 
Upvote 0

Forum statistics

Threads
1,215,365
Messages
6,124,513
Members
449,168
Latest member
CheerfulWalker

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