Copy paste the value between two worksheets in different workbook only if they have same sheet name

2020Rivalry

New Member
Joined
Apr 12, 2022
Messages
35
Office Version
  1. 365
Platform
  1. Windows
Scenario: There have two excel files, one for 2pm and one for 3pm meeting. The files are not exact same, but currently we need to copy some of the data from 2pm file to 3pm one everyday.

Requirements: Only copy the value between two worksheet on two different workbook (2pm and 3pm) if they have the same sheet name. For example, copy paste value from sheet “WK1” workbook “2pm” to sheet “WK1” workbook “3pm”.

3pmTrial.xlsx
ABCDEFGHIJ
1
2Wk3WK3
3
4KPIsTargetAccomplished
5MonTueWedThuFriSatSun
6KPI10
7KPI2L
8KPI32 per Day
90
10KPI4L
WK3
Cell Formulas
RangeFormula
E2E2=CONCAT("WK",B2)


I'm trying with code below but getting this error (Compile error: Invalid or unqualified reference)
VBA Code:
Public Sub insert_Data()

Application.ScreenUpdating = False

Dim wb1, wb2 As Workbook
Set wb1 = Workbooks.Open("G:\DDS\TrialData\2pmTrial.xlsx")
Set wb2 = Workbooks.Open("G:\DDS\TrialData\3pmTrial.xlsx")

Dim sh1 As Worksheets
Set sh1 = Workbooks("3pmTrial.xlsx").Worksheets("WK*")

For Each sh1 In Worksheets
    With Workbooks("3pmTrial.xlsx")
        Workbooks("2pmTrial.xlsx").Worksheets(.Range("E2").Value).Range("D6:J10").Value = .Worksheets(.Range("E2").Value).Range("D6:J10").Value
    End With
Next

Application.ScreenUpdating = True
 
End Sub

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.
Hi Alex,
example for 8.45 file:
Daily DDS (8.45am) Yr2022 v2 ExampleFile.xlsx
ABCDEFGHIJKLMNOPQRST
1qqq- Daily Direction Setting Week no:14WK14
2KPIsTargetAccomplished
3MonTueWedThuFriSatSun
4www11100000
5eeeLLLLLL
6rrr2222 per Day2222
7222200010
8ttt333LLLLLL
9
10qqq Performance
11yyy4443/wk0000
125550000
13uuu6665/wk0010
14777
15888
16iiii999< 12 / Wk91
17000
181111
192222
203333
21ooo4444<0.5 / Wk
225555< 0.2 /Wk
23ppp6666< 1 / Wk0100
24aaa3 per Wk
25sssNA0001
26dddNA3001
27fffNA1
28777799.9%99.9
29ggg8888NA2
30999996.0%96.6
31
32qqq Compliance
33hhh<0.30.040.120.160.160.16
34jjj<0.20.070.070.070.070.07
35kkk<0.500.060.110.170.17
36lll
37zzz
38xxx
39ccc
40vvv<0.100000
41bbb<2000.430.570.57
42nnn1
43mmm>85%100%
44qqqqPass/ Fail
45wwww1
46eeee1 / day0000
47rrrr86%NIL86%100%100%
48tttt100%100%100%100%100%
49yyyy86%NIL100%88%100%
50uuuu100%100%100%100%100%
51iiii<0.30%-0.04-0.16-0.040.20
52oooo<0.30%-0.02-0.11-0.020.10
53aaaa<0.30%-0.02-0.05-0.030.10
54
55Lab Use
56ssss53.5
57dddd98%
58ffff
59gggg≤ ±0.230.47
60hhhh≤ ±0.23-0.04
61jjjj95%100%
62kkkkNA2/24/4maintenance 3/33/3
63llllNA5101010
64zzzz00000
65xxxx00000
66cccc50000
67vvvv50000
68bbbb≤ ±0.230.14-0.25-1.131.79
69nnnn≤ ±0.230.56-0.74-0.13-0.23
70
71Main Losses
72DateIssueInitial Root CauseActionStatus
73x xxxxxxxxxxxxxx
74x1 xx1xxx1xxxx1xxxxx1
75
76
77
78
79
80
81
82
83
84
85
86
87Daily Action Plan
88ActionResponsibleTimelineStatus
89yyyyyy
90
91
92
93Follow up
94ActionResponsibleTimelineStatus
95zzzzzzzzz
96
97
98
99
100
101
102
103
WK14
Cell Formulas
RangeFormula
J1J1=CONCAT("WK",$H$1)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G49Cellcontains a blank value textYES
G49Cell Value<0.86textNO
F47Cellcontains a blank value textYES
F47Cell Value<0.86textNO
G47Cellcontains a blank value textYES
G47Cell Value<0.86textNO
G48Cellcontains a blank value textYES
G48Cell Value<1textNO
F49Cellcontains a blank value textYES
F49Cell Value<0.86textNO
H50Cellcontains a blank value textYES
H50Cell Value<1textNO
H49Cellcontains a blank value textYES
H49Cell Value<0.86textNO
H48Cellcontains a blank value textYES
H48Cell Value<1textNO
E50Cellcontains a blank value textYES
E50Cell Value<1textNO
E49Cellcontains a blank value textYES
E49Cell Value<0.86textNO
E48Cellcontains a blank value textYES
E48Cell Value<1textNO
E47Cellcontains a blank value textYES
E47Cell Value<0.86textNO
F51:H53Cell Value>0.3textNO
G50Cellcontains a blank value textYES
G50Cell Value<1textNO
F50Cellcontains a blank value textYES
F50Cell Value<1textNO
F48Cellcontains a blank value textYES
F48Cell Value<1textNO
H47Cellcontains a blank value textYES
H47Cell Value<0.86textNO


Example for 9.45 file:
Daily DDS (9.45am) Y2022 ExampleFile.xlsx
ABCDEFGHIJKLMNOPQRST
1
2Meeting Venue: AttendeesMonTueWedThuFriSatSun
3Time: 1
4Revision:2
53
64
75
86
97
108
119
1210
13
14qqq - Daily Direction Setting Week: 14
15KPIsTargetMachineAccomplished
16MonTueWedThuFriSatSun
17www1110ALL0000
18eeeLALLLLLLL
19rrr2222 per DayALL2222
2022220ALL0100
21ttt333LALLLLLLL
22yyy4443/wkALL0000
23555ALL0000
24uuu6665/wkALL0010
25777
26888
27iiii999< 10 / WkALL9100
28000
291111
302222
313333
32ooo4444<0.5 / WkALL0000
335555< 0.2 /WkALL0000
34ppp6666< 1.3 / WkALL0100
35aaa3 per WkALL1000
36sssNAALL00010
37dddNAALL30100
38fffNAALL1
39777799.9%ALL99.9
40ggg8888NAALL2
41999996.0%ALL96.6
42--NANAFriMonTueWedThur
43--95%NA2/2Verification & Training program2/200
44-NANA5500
45-NANA0076
46-5NA0000
47-5NA0000
48--95%NA2/22/22/2Transducer replaced & Leakage Check3/3
49-NANA55510
50-NANA0000
51-5NA4001
52-5NA0000
53--< 5 / dayALL03110
54-< 5 / dayALL22100
55-< 2 / dayALL00000
56-< 2 / dayALL00000
57-< 1 / dayALL00000
58-< 2 / dayALL00000
59
60Main Losses
61DateIssueInitial Root CauseActionStatus
62x xxxxxxxxxxxxxx
63x1 xx1xxx1xxxx1xxxxx1
64x2xx2xxx2xxxx2Closed
65x3xx3xxx3xxxx3closed
66x4xx4xxx4xxxx4
67
68
69
70
71
72
73
74Daily Action Plan
75ActionResponsibleTimelineStatus
76
77
78
79
80Follow up
81ActionResponsibleTimelineStatus
82
83
84
85
86
87
88
89
90
WK14


Current VBA Code:
VBA Code:
Public Sub insert_Data()

Application.ScreenUpdating = False

Dim wb1 As Workbook, wb2 As Workbook                    ' Need to edit every year (the new files location)
Set wb1 = Workbooks.Open("G:\DDS\Daily DDS (8.45am) Yr2022 v2 ExampleFile.xlsx")
Set wb2 = Workbooks.Open("G:\DDS\Daily DDS (9.45am) Y2022 ExampleFile.xlsm")

Dim sh1 As Variant
Dim sh2 As Worksheet

For Each sh1 In wb1.Worksheets

    If UCase(sh1.Name) Like "WK*" Then
        On Error Resume Next
            Set sh2 = wb2.Worksheets(sh1.Name)
        On Error GoTo 0
        
        If Not sh2 Is Nothing Then
            sh2.Range("B17:D21").Value = sh1.Range("B4:D8").Value
            sh2.Range("F17:L21").Value = sh1.Range("E4:K8").Value ' safety incident, safety trigger, pulsar, quality trigger
            sh2.Range("B22:D41").Value = sh1.Range("B11:D30").Value
            sh2.Range("F22:L41").Value = sh1.Range("E11:K30").Value ' quality performance
            sh2.Range("B62:S74").Value = sh1.Range("B73:S85").Value ' main losses, need to adjust the row height manually
            sh2.Range("B78:S80").Value = sh1.Range("B89:S91").Value ' daily action plan
            sh2.Range("B84:S91").Value = sh1.Range("B95:S102").Value ' follow up
        End If
    End If
Next

Application.ScreenUpdating = True
 
End Sub

So problem is existing for main losses, daily action plan, and follow up table. This is because currently my code is just copy pasting the entire table value including the blanks, however this is not correct (should only paste when there have value). I have highlighted those 8.45 data in yellow, the data that added later is highlighted in red. I wish there is a code that can check how many rows in main losses, daily action plan, and follow up table are used, and only copy paste those data into 9.45 file.

Thanks!!!
 
Upvote 0
I don't really understand what you are trying to do. Your 9.45 sheet does not really line up with your 8.45 sheet.
If the 8.45 is variable the 9.45 sheet will be variable as well.
Below is some code that addresses the 8.45 variability but you will need to tackle the 9.45 side yourself.
You will have to do something similar on the 9.45 side to find the sections. Insert a number of rows and paste in the data.

This function is pretty ugly but will get the 3 sections you asked for 8.45
The sub under it is your sub with the changes to call the function.

VBA Code:
Function findRng(sh1 As Variant, ByVal strFind As String) As Range

    ' Find start and end of the 3 sections
    Dim foundRow As Long, startRow As Long, endRow As Long
    
    Select Case strFind
    
        Case "Main Losses"
            ' find start of section
            strFind = "Main Losses"
            With Application
                foundRow = .IfError(.Match(strFind, sh1.Range("B:B"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng = Nothing
                Exit Function
            End If
            startRow = foundRow + 2
            
            ' find next section
            strFind = "Daily Action Plan"
            With Application
                foundRow = .IfError(.Match(strFind, sh1.Range("B:B"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng = Nothing
                Exit Function
            End If
            
            endRow = sh1.Range("B" & foundRow).End(xlUp).Row
            If endRow < startRow Then
                Set findRng = Nothing
                Exit Function
            End If
            
        Case "Daily Action Plan"
            ' find start of section
            strFind = "Daily Action Plan"
            With Application
                foundRow = .IfError(.Match(strFind, sh1.Range("B:B"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng = Nothing
                Exit Function
            End If
            startRow = foundRow + 2
            
            ' find next section
            strFind = "Follow up"
            With Application
                foundRow = .IfError(.Match(strFind, sh1.Range("B:b"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng = Nothing
                Exit Function
            End If
            
            endRow = sh1.Range("B" & foundRow).End(xlUp).Row
            If endRow < startRow Then
                Set findRng = Nothing
                Exit Function
            End If
               
        Case "Follow up"
            ' find start of section
            strFind = "Follow up"
            With Application
                foundRow = .IfError(.Match(strFind, sh1.Range("B:b"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng = Nothing
                Exit Function
            End If
            startRow = foundRow + 2
            
            ' Last section on sheet - so get last data row
            endRow = sh1.Range("B" & Rows.Count).End(xlUp).Row
            If endRow < startRow Then
                Set findRng = Nothing
                Exit Function
            End If
        
    End Select
    
    Set findRng = sh1.Range(sh1.Cells(startRow, "B"), sh1.Cells(endRow, "B"))
            
End Function


Modified main routine

VBA Code:
Public Sub insert_Data()

Application.ScreenUpdating = False

Dim wb1 As Workbook, wb2 As Workbook                    ' Need to edit every year (the new files location)
Set wb1 = Workbooks.Open("G:\DDS\Daily DDS (8.45am) Yr2022 v2 ExampleFile.xlsx")
Set wb2 = Workbooks.Open("G:\DDS\Daily DDS (9.45am) Y2022 ExampleFile.xlsm")

Dim sh1 As Variant
Dim sh2 As Worksheet

Dim rngsh1 As Range

For Each sh1 In wb1.Worksheets

    If UCase(sh1.Name) Like "WK*" Then
        On Error Resume Next
            Set sh2 = wb2.Worksheets(sh1.Name)
        On Error GoTo 0
        
        If Not sh2 Is Nothing Then
            sh2.Range("B17:D21").Value = sh1.Range("B4:D8").Value
            sh2.Range("F17:L21").Value = sh1.Range("E4:K8").Value ' safety incident, safety trigger, pulsar, quality trigger
                      
            sh2.Range("B22:D41").Value = sh1.Range("B11:D30").Value
            sh2.Range("F22:L41").Value = sh1.Range("E11:K30").Value ' quality performance

'            sh2.Range("B62:S74").Value = sh1.Range("B73:S85").Value ' main losses, need to adjust the row height manually
            Set rngsh1 = findRng(sh1:=sh1, strFind:="Main Losses").Resize(, 18)
            sh2.Range("B62").Resize(rngsh1.Rows.Count, rngsh1.Columns.Count).Value = rngsh1.Value
            
'            sh2.Range("B78:S80").Value = sh1.Range("B89:S91").Value ' daily action plan
            Set rngsh1 = findRng(sh1:=sh1, strFind:="Daily Action Plan").Resize(, 18)
            sh2.Range("B78").Resize(rngsh1.Rows.Count, rngsh1.Columns.Count).Value = rngsh1.Value
            
'            sh2.Range("B84:S91").Value = sh1.Range("B95:S102").Value ' follow up
            Set rngsh1 = findRng(sh1:=sh1, strFind:="Follow up").Resize(, 18)
            sh2.Range("B84").Resize(rngsh1.Rows.Count, rngsh1.Columns.Count).Value = rngsh1.Value
            
        End If
    End If
Next

Application.ScreenUpdating = True
 
End Sub
 
Upvote 0
Hi Alex,

Error message appear when I try to run your code run-time error '91': Object variable and With block variable not set. Highlighting Set rngsh1 = findRng(sh1:=sh1, strFind:="Daily Action Plan").Resize(, 18). Can you help me?

VBA Code:
Public Sub insert_Data()

Application.ScreenUpdating = False

Dim wb1 As Workbook, wb2 As Workbook                    ' Need to edit every year (the new files location)
Set wb1 = Workbooks.Open("G:\DDS\Daily DDS (8.45am) Yr2022 v2 ExampleFile.xlsx")
Set wb2 = Workbooks.Open("G:\DDS\Daily DDS (9.45am) Y2022 ExampleFile.xlsm")

Dim sh1 As Variant
Dim sh2 As Worksheet

Dim rngsh1 As Range

For Each sh1 In wb1.Worksheets

    If UCase(sh1.Name) Like "WK*" Then
        On Error Resume Next
            Set sh2 = wb2.Worksheets(sh1.Name)
        On Error GoTo 0
        
        If Not sh2 Is Nothing Then
            sh2.Range("B17:D21").Value = sh1.Range("B4:D8").Value
            sh2.Range("F17:L21").Value = sh1.Range("E4:K8").Value ' safety incident, safety trigger, pulsar, quality trigger
                      
            sh2.Range("B22:D41").Value = sh1.Range("B11:D30").Value
            sh2.Range("F22:L41").Value = sh1.Range("E11:K30").Value ' quality performance

'            sh2.Range("B62:S72").Value = sh1.Range("B73:S85").Value ' main losses, need to adjust the row height manually
            Set rngsh1 = findRng(sh1:=sh1, strFind:="Main Losses").Resize(, 18)
            sh2.Range("B62").Resize(rngsh1.Rows.Count, rngsh1.Columns.Count).Value = rngsh1.Value
            
'            sh2.Range("B76:S78").Value = sh1.Range("B89:S91").Value ' daily action plan
            Set rngsh1 = findRng(sh1:=sh1, strFind:="Daily Action Plan").Resize(, 18)
            sh2.Range("B76").Resize(rngsh1.Rows.Count, rngsh1.Columns.Count).Value = rngsh1.Value
            
'            sh2.Range("B82:S89").Value = sh1.Range("B95:S102").Value ' follow up
            Set rngsh1 = findRng(sh1:=sh1, strFind:="Follow up").Resize(, 18)
            sh2.Range("B82").Resize(rngsh1.Rows.Count, rngsh1.Columns.Count).Value = rngsh1.Value
            
        End If
    End If
Next

Application.ScreenUpdating = True
 
End Sub

Can you explain to me why my 9.45 sheet does not really line up with 8.45 sheet....For finding main losses, daily action plan, and follow up, I think the code will have some difference with findRng (8.45 one) as in 9.45 I only need to know the startrow to insert 8.45 data, am I correct?

I truly appreciate your help. Thanks!!
 
Upvote 0
The error you are getting would indicate that the phrase "Daily Action Plan" does not exist in your spreadsheet.
If you believe it does go to the 8.45 sheet hit find Ctrl+F copy in the phrase and then select Match Entire Cell Contents.
If it can't find it then there is something different in how it is entered in the spreadsheet. Match is not case sensitive but if you have an extra space in there somewhere say at the begining or the end it won't find it.
 
Upvote 0
Hi Alex,

can you help me check my code. It does give me the result I want, even with the error pop out...

VBA Code:
Option Explicit

Public Sub insert_Data()

Application.ScreenUpdating = False

Dim wb1 As Workbook, wb2 As Workbook                    ' Need to edit every year (the new files location)
Set wb1 = Workbooks.Open("G:\DDS\Daily DDS (8.45am) Yr2022 v2 ExampleFile.xlsx")
Set wb2 = Workbooks.Open("G:\DDS\Daily DDS (9.45am) Y2022 ExampleFile.xlsm")

Dim sh1 As Variant
Dim sh2 As Worksheet

Dim rngsh1 As Range
Dim rngsh2 As Range

Dim foundRow As Long, startRow As Long, endRow As Long

For Each sh1 In wb1.Worksheets

    If UCase(sh1.Name) Like "WK*" Then
        On Error Resume Next
            Set sh2 = wb2.Worksheets(sh1.Name)
        On Error GoTo 0
        
        If Not sh2 Is Nothing Then
            sh2.Range("B17:D21").Value = sh1.Range("B4:D8").Value
            sh2.Range("F17:L21").Value = sh1.Range("E4:K8").Value ' safety incident, safety trigger, pulsar, quality trigger
                      
            sh2.Range("B22:D41").Value = sh1.Range("B11:D30").Value
            sh2.Range("F22:L41").Value = sh1.Range("E11:K30").Value ' quality performance

'            sh2.Range("B62:S72").Value = sh1.Range("B73:S85").Value ' main losses, need to adjust the row height manually
            Set rngsh1 = findRng(sh1:=sh1, strFind:="Main Losses").Resize(, 18)
            Set rngsh2 = findRng1(sh2:=sh2, strFind:="Main Losses").Resize(, 18)
            rngsh1.Copy
            rngsh2.Insert Shift:=xlShiftDown
            
'            sh2.Range("B76:S78").Value = sh1.Range("B89:S91").Value ' daily action plan
            Set rngsh1 = findRng(sh1:=sh1, strFind:="Daily Action Plan").Resize(, 18)
            Set rngsh2 = findRng1(sh2:=sh2, strFind:="Daily Action Plan").Resize(, 18)
            rngsh1.Copy
            rngsh2.Insert Shift:=xlShiftDown
            
'            sh2.Range("B82:S89").Value = sh1.Range("B95:S102").Value ' follow up
            Set rngsh1 = findRng(sh1:=sh1, strFind:="Follow up").Resize(, 18)
            Set rngsh2 = findRng1(sh2:=sh2, strFind:="Follow up").Resize(, 18)
            rngsh1.Copy
            rngsh2.Insert Shift:=xlShiftDown
            
        End If
    End If
Next

Application.ScreenUpdating = True
 
End Sub

Function code to find 8.45 data:
VBA Code:
Function findRng(sh1 As Variant, ByVal strFind As String) As Range

    ' Find start and end of the 3 sections
    Dim foundRow As Long, startRow As Long, endRow As Long
    
    Select Case strFind
    
        Case "Main Losses"
            ' find start of section
            strFind = "Main Losses"
            With Application
                foundRow = .IfError(.Match(strFind, sh1.Range("B:B"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng = Nothing
                Exit Function
            End If
            startRow = foundRow + 2
            
            ' find next section
            strFind = "Daily Action Plan"
            With Application
                foundRow = .IfError(.Match(strFind, sh1.Range("B:B"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng = Nothing
                Exit Function
            End If
            
            endRow = sh1.Range("B" & foundRow).End(xlUp).Row
            If endRow < startRow Then
                Set findRng = Nothing
                Exit Function
            End If
            
        Case "Daily Action Plan"
            ' find start of section
            strFind = "Daily Action Plan"
            With Application
                foundRow = .IfError(.Match(strFind, sh1.Range("B:B"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng = Nothing
                Exit Function
            End If
            startRow = foundRow + 2
            
            ' find next section
            strFind = "Follow up"
            With Application
                foundRow = .IfError(.Match(strFind, sh1.Range("B:b"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng = Nothing
                Exit Function
            End If
            
            endRow = sh1.Range("B" & foundRow).End(xlUp).Row
            If endRow < startRow Then
                Set findRng = Nothing
                Exit Function
            End If
               
        Case "Follow up"
            ' find start of section
            strFind = "Follow up"
            With Application
                foundRow = .IfError(.Match(strFind, sh1.Range("B:b"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng = Nothing
                Exit Function
            End If
            startRow = foundRow + 2
            
            ' Last section on sheet - so get last data row
            endRow = sh1.Range("B" & Rows.Count).End(xlUp).Row
            If endRow < startRow Then
                Set findRng = Nothing
                Exit Function
            End If
        
    End Select
    
    Set findRng = sh1.Range(sh1.Cells(startRow, "B"), sh1.Cells(endRow, "B"))
            
End Function

Function code to find startrow in 9.45:
VBA Code:
Function findRng1(sh2 As Variant, ByVal strFind As String) As Range

    ' Find start and end of the 3 sections
    Dim foundRow As Long, startRow As Long
    
    Select Case strFind
    
        Case "Main Losses"
            ' find start of section
            strFind = "Main Losses"
            With Application
                foundRow = .IfError(.Match(strFind, sh2.Range("B:B"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng1 = Nothing
                Exit Function
            End If
            startRow = foundRow + 2
            
        Case "Daily Action Plan"
            ' find start of section
            strFind = "Daily Action Plan"
            With Application
                foundRow = .IfError(.Match(strFind, sh2.Range("B:B"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng1 = Nothing
                Exit Function
            End If
            startRow = foundRow + 2
               
        Case "Follow up"
            ' find start of section
            strFind = "Follow up"
            With Application
                foundRow = .IfError(.Match(strFind, sh2.Range("B:B"), 0), 0)
            End With
            If foundRow = 0 Then
                Set findRng1 = Nothing
                Exit Function
            End If
            startRow = foundRow + 2
        
    End Select
    
    Set findRng1 = sh2.Range(sh2.Cells(startRow, "B"), sh2.Cells(startRow, "S"))
            
End Function
 
Upvote 0
Does your wb1 have more than one sheet starting with WK in it ?
When you get the error go to the immediate box and type in the below including the "?" which is a shortcut for "Print"
? sh1.name
 
Upvote 0
And did you try this and what name did it return.
When you get the error go to the immediate box and type in the below including the "?" which is a shortcut for "Print"
? sh1.name
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,052
Members
452,542
Latest member
Bricklin

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