VBA Run Time Error '1004': Select method of Range Class failed using

Palucci

Banned user
Joined
Sep 15, 2021
Messages
138
Office Version
  1. 365
Platform
  1. Windows
I have a problem, because when I run the macro I get an error like in the title here:
VBA Code:
data_wb.Sheets("Adekwatnosc").Rows("1:1").Select
However, when I go step by step after F8 and go manually to the Adekwatnosc tab, everything is ok. How to fix that the file itself works in the background and goes to the indicated tab.
This is my all code:
VBA Code:
Dim vDate As Date
Dim wbMe As Workbook
Dim data_wb As Workbook
Dim ws As Worksheet
Dim inputbx As String
Dim loc As Range, lc As Long
Dim MyFolder As String, ThisMonth As String
Dim MyFile As String

Set wbMe = ActiveWorkbook
With wbMe.Sheets("input_forecast").Rows("1:1")
    .Copy
    .PasteSpecial Paste:=xlPasteValues
    .NumberFormat = "YYYY-MM-DD"
  End With
   

MyFolder = "C:\Users\V1410190\Documents\FOLDERY ROBOCZE"



MyFile = Dir(MyFolder & "\filee*.xlsm")


If MyFile <> "" Then

Set data_wb = Workbooks.Open(MyFolder & "\" & MyFile, UpdateLinks:=0)

Else
Exit Sub
End If

Application.ThisWorkbook.UpdateLinks = xlUpdateLinksNever '2
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.AskToUpdateLinks = False



data_wb.Sheets("Adekwatnosc").Rows("1:1").Select
 
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "YYYY-MM-DD"
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try replacing this part ...
Rich (BB code):
data_wb.Sheets("Adekwatnosc").Rows("1:1").Select
  
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "YYYY-MM-DD"

with this part:
VBA Code:
With data_wb.Sheets("Adekwatnosc").Rows("1:1")
    .Copy
    .Parent.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    .NumberFormat = "YYYY-MM-DD"
End With
Application.CutCopyMode = False
 
Upvote 0
You cannot select on a non active sheet, try replacing this
VBA Code:
data_wb.Sheets("Adekwatnosc").Rows("1:1").Select
 
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "YYYY-MM-DD"
with
VBA Code:
With data_wb.Sheets("Adekwatnosc").Rows("1:1")
   .Value = .Value
   .NumberFormat = "YYYY-MM-DD"
End With
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

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