Copy some cells from "ALL" sheets to specific sheet !

bigmak

New Member
Joined
Sep 8, 2020
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
hello everybody
i have a workbook and i want copy some cells of ALL sheets to specific sheet
for example copy value of salary and tax cells of all sheets of persons to sheet "names".
i record a macro to ["copy H7 and F9 cells of sheet "john" to B2 and C2 cells of sheet "names" ] and send code below :
VBA Code:
Sub Macro1()
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "=john!R[5]C[6]"
    Range("C2").Select
    ActiveCell.FormulaR1C1 = "=john!R[7]C[3]"
End Sub
i send some picture of my workbook
 

Attachments

  • exx 2.jpg
    exx 2.jpg
    51.5 KB · Views: 6
  • exxx 1.jpg
    exxx 1.jpg
    50.6 KB · Views: 6
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try this:

VBA Code:
Sub CopyCells()
  Dim sh As Worksheet
  For Each sh In Sheets
    If LCase(sh.Name) <> LCase("names") Then
      Sheets("names").Range("A" & Rows.Count).End(3)(2).Resize(1, 3).Value = Array(sh.Name, sh.[H7], sh.[F9])
    End If
  Next
End Sub
 
Upvote 0
Try this:

VBA Code:
Sub CopyCells()
  Dim sh As Worksheet
  For Each sh In Sheets
    If LCase(sh.Name) <> LCase("names") Then
      Sheets("names").Range("A" & Rows.Count).End(3)(2).Resize(1, 3).Value = Array(sh.Name, sh.[H7], sh.[F9])
    End If
  Next
End Sub
your code work great (y) (y) (y) (y) (y)
but one little problem i dont want copy sheet NAMES just want copy sh.[H7], sh.[F9]

and extra question could you improve this code that work when "names" sheet in another workbook ??
 
Upvote 0
I put the names of the sheets to be safe. Otherwise, you have to put several validations, if the name exists as a sheet, if it is well written, etc.
 
Upvote 0
could you improve this code that work when "names" sheet in another workbook ??
 
Upvote 0
could you improve this code that work when "names" sheet in another workbook ??
Try this:

VBA Code:
Sub CopyCells()
  Dim sh As Worksheet
  For Each sh In Workbooks("another_wokbook_name.xlsx").Sheets
    If LCase(sh.Name) <> LCase("names") Then
      Sheets("names").Range("A" & Rows.Count).End(3)(2).Resize(1, 3).Value = Array(sh.Name, sh.[H7], sh.[F9])
    End If
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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