VBA: Pull Data From Multiple Sheet With Specific Sheet & Cell

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all..

the code working well to pull data from multiple sheets (all sheet) into 1 sheet in the same workbook.
i want to modified can pull data with specific name sheet and specific cell
VBA Code:
Sub Consolidate_Worksheets_To_Master_Using_Arrays()
    Dim ws          As Worksheet
    Dim sh          As Worksheet
    Dim a           As Variant
    Dim i           As Long
    Dim r           As Long
   
    Application.ScreenUpdating = False
        Set sh = ThisWorkbook.Worksheets("master")
        sh.Range("B9").CurrentRegion.Offset(1).ClearContents
        r = 2
       
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> "master" And ws.Name <> "etc.." Then
                With ws
                    a = Array("G10", "H10", "J10", "I2", "I9")
                    For i = LBound(a) To UBound(a)
                        a(i) = .Range(a(i)).Value
                        If i >= 100000 Then a(i) = Val(AlphaNum(CStr(a(i))))
                    Next i
                    sh.Range("A" & r).Resize(, UBound(a) + 1).Value = a
                    r = r + 1
                End With
            End If
        Next ws
    Application.ScreenUpdating = True
End Sub
Function AlphaNum(txt As String, Optional numOnly As Boolean = True) As String
    With CreateObject("VBScript.RegExp")
        .Pattern = IIf(numOnly = True, "\D+", "-?\d+(\.\d+)?")
        .Global = True
        AlphaNum = .Replace(txt, "")
    End With
End Function
my question like this
1. my target in sheet "Master" start col B9 down right till K13 with my data (will be pulled) in sheet "Summary & Country" in cell with number "yellow" shading (rows KEEP IN THERE - not change rows)
2. i want to pull data from sheet "summary & country" into sheet "master" based on name of city/country like Hongkong, Bangkong, UsA....etc
3. my desired result in sheet "master" with criteria:
- if in cell A9 is Hongkong -- pull data from sheet "summary & country" into sheet 'master" and placing in cell B9 till K9.
- if in cell A10 is Bangkok -- pull data from sheet "summary & country" into sheet 'master" and placing in cell B10 till K10.
- if in cell A11 is USA -- pull data from sheet "summary & country" into sheet 'master" and placing in cell B11 till K11.
- etc...
4. i want when running macro, at first show msg box "select city...." then run/click ok
5. for sample please, check in my first OP

this my link file Loading Google Sheets
across posting VBA : Pull Data From Multiple Sheet Into 1 Sheet Based On Criteria

thank you
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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