Find and copy a specific cell in multiple sheets and paste it in master sheet

Rafay

New Member
Joined
Nov 7, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a query
I have an excel file containing multiple sheets of sales invoices. I want to copy some information like client name, date, total, etc and paste it in master sheet. Currently I am using a macro to copy the information in same cell across all the sheets. To do this, I go to the cell that I want to copy from other sheets and run this macro:
Sub AutoFillSheetNames()
'Update by Extendoffice
Dim ActRng As Range
Dim ActWsName As String
Dim ActAddress As String
Dim Ws As Worksheet
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set ActRng = Application.ActiveCell
ActWsName = Application.ActiveSheet.Name
ActAddress = ActRng.Address(False, False)
Application.ScreenUpdating = False
xIndex = 0
For Each Ws In Application.Worksheets
If Ws.Name <> ActWsName Then
ActRng.Offset(xIndex, 0).Value = "='" & Ws.Name & "'!" & ActAddress
xIndex = xIndex + 1
End If
Next
Application.ScreenUpdating = True
End Sub
The problem is that the total of invoices is not in the same cell. So I need a macro to search for "Grand Total" in each sheet and copy the cell next to it and paste it in master sheet.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi Rafay,

maybe try

VBA Code:
Sub MrE1221436_161380B_GTColA_Formula()
'www.mrexcel.com/board/threads/find-and-copy-a-specific-cell-in-multiple-sheets-and-paste-it-in-master-sheet.1221436/
'Grand Total is in Column A last row
  Dim wsMaster      As Worksheet
  Dim ws            As Worksheet
  
  Application.ScreenUpdating = False
  Set wsMaster = ActiveSheet
  For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> wsMaster.Name Then
      wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = _
          "='" & ws.Name & "'!" & ws.Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Address(0, 0)
    End If
  Next ws
  Set wsMaster = Nothing
  Application.ScreenUpdating = True
End Sub

VBA Code:
Sub MrE1221436_161380B_GTColA_Values()
'Grand Total is in Column A last row
  Dim wsMaster      As Worksheet
  Dim ws            As Worksheet

  Application.ScreenUpdating = False
  Set wsMaster = ActiveSheet
  For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> wsMaster.Name Then
      wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = ws.Name
      wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = ws.Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Address(0, 0)
      wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = ws.Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value
    End If
  Next ws
  Set wsMaster = Nothing
  Application.ScreenUpdating = True
End Sub

VBA Code:
Sub MrE1221436_161380B_GTAnywhere_Values()
'Grand Total is anywhere in the sheet
  Dim wsMaster      As Worksheet
  Dim ws            As Worksheet
  Dim rngFound      As Range
  
  Application.ScreenUpdating = False
  Set wsMaster = ActiveSheet
  For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> wsMaster.Name Then
      With ws.UsedRange
        Set rngFound = .Find("Grand Total", LookIn:=xlValues, SearchDirection:=xlPrevious)
        If Not rngFound Is Nothing Then
          wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = ws.Name
          wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = rngFound.Offset(0, 1).Address(0, 0)
          wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = rngFound.Offset(0, 1).Value
        End If
      End With
    End If
  Next ws
  Set rngFound = Nothing
  Set wsMaster = Nothing
  Application.ScreenUpdating = True
End Sub

Ciao,
Holger
 
Upvote 0
Solution
Hi Rafay,

maybe try

VBA Code:
Sub MrE1221436_161380B_GTColA_Formula()
'www.mrexcel.com/board/threads/find-and-copy-a-specific-cell-in-multiple-sheets-and-paste-it-in-master-sheet.1221436/
'Grand Total is in Column A last row
  Dim wsMaster      As Worksheet
  Dim ws            As Worksheet
 
  Application.ScreenUpdating = False
  Set wsMaster = ActiveSheet
  For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> wsMaster.Name Then
      wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = _
          "='" & ws.Name & "'!" & ws.Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Address(0, 0)
    End If
  Next ws
  Set wsMaster = Nothing
  Application.ScreenUpdating = True
End Sub

VBA Code:
Sub MrE1221436_161380B_GTColA_Values()
'Grand Total is in Column A last row
  Dim wsMaster      As Worksheet
  Dim ws            As Worksheet

  Application.ScreenUpdating = False
  Set wsMaster = ActiveSheet
  For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> wsMaster.Name Then
      wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = ws.Name
      wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = ws.Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Address(0, 0)
      wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = ws.Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value
    End If
  Next ws
  Set wsMaster = Nothing
  Application.ScreenUpdating = True
End Sub

VBA Code:
Sub MrE1221436_161380B_GTAnywhere_Values()
'Grand Total is anywhere in the sheet
  Dim wsMaster      As Worksheet
  Dim ws            As Worksheet
  Dim rngFound      As Range
 
  Application.ScreenUpdating = False
  Set wsMaster = ActiveSheet
  For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> wsMaster.Name Then
      With ws.UsedRange
        Set rngFound = .Find("Grand Total", LookIn:=xlValues, SearchDirection:=xlPrevious)
        If Not rngFound Is Nothing Then
          wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = ws.Name
          wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = rngFound.Offset(0, 1).Address(0, 0)
          wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = rngFound.Offset(0, 1).Value
        End If
      End With
    End If
  Next ws
  Set rngFound = Nothing
  Set wsMaster = Nothing
  Application.ScreenUpdating = True
End Sub

Ciao,
Holger
Thank you very much Holger. Its working perfectly fine. :)
 
Upvote 0
Hi Rafay,

glad we could help here and thanks for the feedback.

Holger
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,746
Members
449,050
Latest member
excelknuckles

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