Copy last cell with number and Paste

eaje92

New Member
Joined
Feb 19, 2018
Messages
16
Hi, I need help in using vba to copy the last cell which contains only a number and then pasting it to the row beside. Assuming the value below the last cell in column one gets updated with a value
For example,

Initial
[TABLE="width: 500"]
<tbody>[TR]
[TD="align: center"]Column 1[/TD]
[TD="align: center"]Column 2[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]NA (this value would get updated) [/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]NA[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]NA[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]NA[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


After 1 iteration
[TABLE="width: 500"]
<tbody>[TR]
[TD="align: center"]Column 1[/TD]
[TD="align: center"]Column 2[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]32[/TD]
[TD="align: center"]*32*
[/TD]
[/TR]
[TR]
[TD="align: center"]NA (Next cell to get updated)[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]NA[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]NA[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


I would like vba to search for the last cell in column 1 which has a number(not "NA") and then copy and pasting it in column 2.

Much appreciated!
 

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
This is assuming columns A and B:

Code:
Sub LastNumber()
On Error Resume Next
Dim x
x = Evaluate("LOOKUP(9.999999999E+307,A:A)")
If Not (IsError(x)) Then Range("B" & Rows.Count).End(xlUp).Offset(1) = x
End Sub
 
Last edited:
Upvote 0
this will do it;
Code:
Sub test()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, 1))
For i = lastrow To 1 Step -1
 If IsNumeric(inarr(i, 1)) Then
  Cells(i, 2) = inarr(i, 1)
  Exit For
 End If
Next i


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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