EXCEL- Wrong Copy Next Cell

sitzalke

New Member
Joined
May 13, 2019
Messages
11
Hi. I have a problem which are my cell wrongly copy data. It supposed to copy really next cell, but it copy the data below next cell. This is the example,

when column "L" is blank or empty, then it will copy next cell in column M.

column Lcolumn M
1
2
33

<tbody>
</tbody>
4
5
6
37


<tbody>
</tbody>

it supposed to be like this,

column Lcolumn M
11
22
33

<tbody>
</tbody>
44
55
66
37

<tbody>
</tbody>


but my output is like this,
it copy cell from below cell in 5.

column Lcolumn M
21
32
33

<tbody>
</tbody>
54
65
76
37

<tbody>
</tbody>

this is my code,
Code:
Sub BlankNcopy()
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 in advance
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
MAybe this then
Code:
Sub BlankNcopy()
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).Value  ' this should be the same line NOT the line below
Next c
Application.ScreenUpdating = True


End Sub
 
Upvote 0
MAybe this then
Code:
Sub BlankNcopy()
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).Value  ' this should be the same line NOT the line below
Next c
Application.ScreenUpdating = True


End Sub

yeah, it works. But, the thing is, it only copy first row when I run the macro. but, if I run twice, only then it will copy all row.

for example,
column L are all blank or empty.

column Lcolumn M
1
2
3
4
5

<tbody>
</tbody>

then I run the macro, the output is like this,
column Lcolumn M
11
2
3
4
5

<tbody>
</tbody>


then I run twice, it be like this,

column Lcolumn M
11
22
33
44
55

<tbody>
</tbody>


my question is, how to make it run only one time to copy all?

Thanks for the reply :)
 
Upvote 0
Try this

Code:
Sub BlankNcopy()
    On Error GoTo Noblanks
    With Range("L2", Range("L" & Rows.Count).End(xlUp))
        .SpecialCells(xlCellTypeBlanks) = "=IF(RC[1]="""","""",RC[1])"
        .Value = .Value
    End With
    Exit Sub
Noblanks:
    MsgBox "No blank cells in col L"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

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