Copy values from Column B to C, stopping at column B's end

jimayers

Board Regular
Joined
Nov 14, 2010
Messages
99
Hi - I am trying to write a code that searches for any value in a cell in column B. If it has a value to copy it to the cell next to it in column C. If it is blank I want it to leave it alone. Then move on to the next cell down in B and repeat..all the way down to my last cell in B.

Here is what I have:
Sub copypaste()


Dim i As Integer
Dim LastRow As Integer 'Long?
ActiveSheet.Range.Cells("B1").Select

LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For i = 1 To LastRow


If ActiveSheet.Range.Cells(i, "B") = "" Then
Selection.Offset(1, 0).Select
ElseIf ActiveSheet.Range.Cells(i, "B") <> Nothing Then
Range.Cells(i, "B").Copy
Range.Cells(i, "C").Paste
End If
Next i

End With
End Sub

Thanks for your help - Jim A
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try this:
Code:
Sub Search_Column_B()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row

    For i = 1 To Lastrow
        If Cells(i, 2) <> xlnull Then Cells(i, 3).Value = Cells(i, 2).Value
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Perhaps I'm not understanding, but couldn't you just copy them all at once?

Code:
Sub CopyBC()
  Range("B1", Range("B" & Rows.Count).End(xlUp)).Copy Destination:=Range("C1")
End Sub
 
Upvote 0
Thank you for your response.
But where there is data in column B, there are open cells to copy to in C.
where there is no data in B, there is in C.
I do not want to copy blank cells over data.
 
Last edited:
Upvote 0
Are you saying neither script given you here work? If they do not then you need to explain better.
where there is date in column B, there are open cells to copy to in C.
where there is no data in B, there is in C.
I do not want to copy blank cells over data.
 
Upvote 0
What do you mean "Cut" you said in Post #1

has a value to copy it to the cell next to it in column C
 
Upvote 0
My Answer Is This - thanks...yours worked. I am not sure about the other, although I overlooked its simplicity. I just did not want to overwrite existing data in C with blanks in B.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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