VBA - extract data plus cell above

mrfatc

New Member
Joined
Feb 29, 2016
Messages
2
Good morning

I’m trying to do some code but didn’t get very far as Im very new at this. Could you please point me in the right direction?

I’m trying to write some code that copies all cells that are above a value in C1. At this time, the value is C1 = 8

The range that I’m looking in, is J2:BJ61.

I’m trying to get the values within the range that are greater than C1 to be in a list starting from B2 and working down, B2, B3, B4 etc

Also, I would like the cell above, in a list starting from A2 and working down, A2, A3 etc

As an example.

K2 = Apples
K3 = 9

J10= Oranges
J11 = 10




Therefore,

K2 is greater than C1, so copy K2 to A2 and K3 to B2
J10 is greater than C1 so copy J10 to A3 and J11 to B3


A2 = Apples (k2), B2 = 9 (K3)
A3 = Oranges (J10), B3 = 10 (J11)

There is no preference for order, as I will sort it later which I know how to do.

Thank you in advanced
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,936
Office Version
  1. 365
Platform
  1. Windows
Welcome to the forum.
Try this:

Code:
Sub a925021()
Dim r As Range
Dim n As Long
For Each r In Range("J2:BJ61")
  If IsNumeric(r.Value) And r.Value > Range("C1").Value Then
    n = Range("A" & Rows.count).End(xlUp).row + 1
    Cells(n, "A").Value = r.Offset(-1).Value
    Cells(n, "B").Value = r.Value
  End If
Next

End Sub
 

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,936
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the reply.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,521
Messages
5,596,645
Members
414,083
Latest member
Mrsash

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
Top