Extract non blank rows and adjacent data

slam

Well-known Member
Joined
Sep 16, 2002
Messages
867
Office Version
  1. 365
  2. 2019
Hi all,

Would greatly appreciate it if someone could lend a hand with a problem I have.

I have a range, A9:G200. I'm looking for non-blank rows in column G. When a value exists (dollar amount), I then want that value displayed in N3, and I want the associated value from column A displayed in L3, and the value from column B displayed in M3. The next non-blank value in column G would then be displayed in N4, L34, and M4 respectively.

The same value could be displayed in column G more than once, but I would want all values listed in column N with the data from the other respective columns.

Thank you
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Code:
Option Explicit


Sub slam()
    Dim lr As Long, c As Range, rng As Range
    lr = Range("G" & Rows.Count).End(xlUp).Row
    Dim start As Long, myrow As Long
    Set rng = Range("G9:G" & lr)
    start = 3
    For Each c In rng
        If c <> "" Then
            myrow = c.Row
            Range("N" & start) = c
            Range("L" & start) = Range("A" & myrow)
            Range("M" & start) = Range("B" & myrow)
            start = start + 1
        End If
    Next c
    MsgBox ("Complete")
End Sub
 
Upvote 0
How about this:

Code:
Sub noBlanks()


    Dim arr
    Dim i As Long, rw As Long
    
    rw = 3
    arr = ActiveSheet.Range("A9:G200")
    For i = LBound(arr) To UBound(arr)
        If arr(i, 7) = "" Then GoTo Skip
        Cells(rw, 14) = arr(i, 7)
        Cells(rw, 12) = arr(i, 1)
        Cells(rw, 13) = arr(i, 2)
        rw = rw + 1
Skip:
    Next
    
End Sub
 
Upvote 0
Here is a formula approach if you are interested in that method.

Formula in N3 is copied down
Formula in L3 is copied across to M3 and down

Excel Workbook
ABCDEFGHIJKLMN
2
3Col A Rw 9Col B Rw 9200
4Col A Rw 12Col B Rw 1235
5Col A Rw 13Col B Rw 13200
6Col A Rw 14Col B Rw 1489
7Col A Rw 15Col B Rw 1552.33
8Col A Rw 18Col B Rw 18145
9Col A Rw 9Col B Rw 9200
10Col A Rw 10Col B Rw 10
11Col A Rw 11Col B Rw 11
12Col A Rw 12Col B Rw 1235
13Col A Rw 13Col B Rw 13200
14Col A Rw 14Col B Rw 1489
15Col A Rw 15Col B Rw 1552.33
16Col A Rw 16Col B Rw 16
17Col A Rw 17Col B Rw 17
18Col A Rw 18Col B Rw 18145
19
Non blank rows
 
Upvote 0
Thanks to all who replied. I went with the formula option, and it works perfectly.
 
Upvote 0

Forum statistics

Threads
1,214,379
Messages
6,119,190
Members
448,874
Latest member
Lancelots

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