Macro to extract specific text

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi All

I have two worksheets 'Dashboard' and 'Data' in the same workbook. I need to extract specific text from Data into Dashboard. The number of rows in Data are unknown.

Let the unknown row as x, column as number (e.g. column D =4)

If Data!(x,4) = "3", then to extract the data below into Dashboard from row 24 and onwards:

Dashboard!B24.value = Data!(x,1)
Dashboard!C24.value = Data!(x,2)
Dashboard!G24.value = Data!(x,5)
Dashboard!AA24.value = Data!(x, 6)
Dashboard!AC24.value = Data!(x, 7)

The the next row of data will be in row 25 of Dashboard and onwards.

Please could anyone give me an idea how to create this macro? Many thanks.
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Give this a try. Copy to standard code module1.
VBA Code:
Sub t()
Dim c As Range, aryD As Variant, aryS As Variant, r As Long, sh1 As Worksheet, sh2 As Worksheet, i As Long
aryD = Array("B", "C", "G", "AA", "AC")
aryS = Array(1, 2, 5, 6, 7)
Set sh1 = Sheets("Data")
Set sh2 = Sheets("Dashboard")
    With sh1
        r = 24
        For Each c In .Range("D2", .Cells(Rows.Count, 4).End(xlUp))
            If c = 3 Then
                For i = LBound(aryS) To UBound(aryS)
                    sh2.Range(aryD(i) & r) = sh1.Cells(c.Row, aryS(i)).Value
                Next
                r = r + 1
            End If
        Next
    End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,857
Messages
6,121,948
Members
449,056
Latest member
FreeCricketId

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