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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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,224,585
Messages
6,179,703
Members
452,938
Latest member
babeneker

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