Macro to Extract Specific cell data depending on Row Header not Row Number

hyplyx

New Member
Joined
May 12, 2022
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi All,
I am currently using this code provided by @John_w in this thread.

Rich (BB code):
Public Sub Copy_Values_From_Workbooks()
 
    Dim matchWorkbooks As String
    Dim destSheet As Worksheet, r As Long
    Dim folderPath As String
    Dim wbFileName As String
    Dim fromWorkbook As Workbook
 
    'Folder path and wildcard workbook files to import cells from
 
    matchWorkbooks = "C:\folder\path\*.xls"                                             'CHANGE THIS
 
    'Define destination sheet
 
    Set destSheet = ActiveWorkbook.Worksheets("Summary")                                'CHANGE THIS
 
    destSheet.Cells.Clear
    r = 0
 
    Application.ScreenUpdating = False
         
    folderPath = Left(matchWorkbooks, InStrRev(matchWorkbooks, "\"))
    wbFileName = Dir(matchWorkbooks)
    While wbFileName <> vbNullString
        Set fromWorkbook = Workbooks.Open(folderPath & wbFileName)
        With fromWorkbook.Worksheets(1)
            destSheet.Range("B8:G8").Offset(r).Value = .Range("E25041'>Q10:V10").Value
            destSheet.Range("H8:M8").Offset(r).Value = .Range("E25041'>Q13:V13").Value
            destSheet.Range("N8:S8").Offset(r).Value = .Range("Q16:V16").Value
            destSheet.Range("A8").Offset(r).Value = .Range("B14").Value
            r = r + 1
        End With
        fromWorkbook.Close savechanges:=False
        DoEvents
        wbFileName = Dir
    Wend
 
    Application.ScreenUpdating = True
 
    MsgBox "Finished"
 
End Sub

It worked great but I want to change it so the ranges in red (Range("X#:X#").Value) are related to a row heading found in column B instead of a specific row number. I am still wanting to pull data from column Q but instead of there being a row number I want it to relate to a row header round in column B (sometimes the name of the row could be found in B22-24 sometimes it could be B2-4 but the row header would always be Sample 1, Sample 2, Sample 3 and the data I want to pull is always found the column Q).

I hope my explanation is clear. Does anyone have ideas on how to solve this?

Thank you for any suggestions and help in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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