VBA to Populate columm based on criteria

Joined
Oct 15, 2018
Messages
5
Hi

I have tried to create the VBA code below to populate values in column B but cannot get it to work.

Essentially my spreadsheet looks like this with numbers and text in column A. Whereever there is a numeric value in column A, I would like to copy it and place it one cell above in column B.

So in the first instance, it would take the value from A3 (0.1151) and place next to Product
in B2:

A1
A2 product
A3 0.1151
A4
A5
A6 Open
A7 -0.0141
A8


This is the code I have so far:

Sub Rearrange()


last = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To last
If IsNumeric(Cells(i, "A")) = "False" Then


'Cells(i, "A").Copy
'Cells(i - 1, "B").Select
'Selection.PasteSpecial Paste:=xlPasteValues
Resume Next


Else:


r = Cells(i, "A").Row
rpre = r - 1
MsgBox rpre
Cells(rpre, 2).Value = Cells(i, "A").Value
End If


Next i


End Sub

Thanks

AEM
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi & welcome to MrExcel
How about
Code:
Sub MoveNumbers()
   Dim rng As Range
   For Each rng In Range("A:A").SpecialCells(xlConstants, xlNumbers).Areas
      rng.Offset(-1, 1).Value = rng.Value
   Next rng
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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