Extracting Data

PG626

New Member
Joined
Dec 23, 2024
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I would like to extract all the "No's" into another sheet and will have a filter of the award fields and yield which AWD-xxxx had a No.

1736356574229.png
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this and let me know if it works. Untested here.

VBA Code:
Sub ExtractNos()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim i As Long
    Dim j As Long
    Dim lastRow As Long
    Dim outputRow As Long
    Dim col As Long
    Dim colHeaders As Variant

    Set ws1 = ThisWorkbook.Sheets("Sheet1")
    Set ws2 = ThisWorkbook.Sheets("Sheet2")

    colHeaders = Array("C", "D", "E", "F", "G", "H", "I") ' Columns to check

    ws2.Cells.Clear ' Clear Sheet2 before copying

    ' Set header for Sheet2
    ws2.Range("A1").Value = "Row"
    ws2.Range("B1").Value = "Column"
    ws2.Range("C1").Value = "Value"
    ws2.Range("D1").Value = "Award Field"

    outputRow = 2

    ' Loop through each row in Sheet1
    lastRow = ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row
    For i = 2 To lastRow
        ' Loop through each specified column
        For j = LBound(colHeaders) To UBound(colHeaders)
            col = ws1.Columns(colHeaders(j)).Column
            If ws1.Cells(i, col).Value = "No" Then
                ws2.Cells(outputRow, 1).Value = i
                ws2.Cells(outputRow, 2).Value = colHeaders(j)
                ws2.Cells(outputRow, 3).Value = ws1.Cells(i, col).Value
                ws2.Cells(outputRow, 4).Value = "AWD-" & Format(outputRow - 1, "0000")
                outputRow = outputRow + 1
            End If
        Next j
    Next i

    MsgBox "Extraction complete!"
End Sub
 
Upvote 0

PG626,​

Here's how I interpret your question.
Assuming data in Sheet1 and the result in Sheet2.
Code:
Sub test()
    Dim a, i&, ii&, n&
    a = Sheets("sheet1").[a1].CurrentRegion.Value2
    ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 2)
    b(1, 1) = "Award Fields": b(1, 2) = "AWD No": n = 1
    For ii = 3 To UBound(a, 2)
        For i = 2 To UBound(a, 1)
            If a(i, 1) = "" Then a(i, 1) = a(i - 1, 1)
            If a(i, ii) = "No" Then
                n = n + 1
                b(n, 1) = a(i, 1) & IIf(a(i, 2) <> "", " / " & a(i, 2), "")
                b(n, 2) = a(1, ii)
            End If
        Next
    Next
    With Sheets("sheet2").Columns("a:b")
        .ClearContents
        .Resize(n) = b
        .Columns.AutoFit
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,759
Messages
6,186,861
Members
453,380
Latest member
ShaeJ73

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