It is showing error 1004 on ** --- ** line in this code. PLease help
Sub test()
Workbooks("OI ANALYSIS.xlsm").Activate
Sheet3.Select
Range("A16:C16").Copy
Sheet4.Select
**Range("B2").End(xlDown).Offset(1, 0).Select**
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Application.OnTime Now + TimeValue("00:00:01"), "test"
End Sub
Try this-
Sub test()
Workbooks("OI ANALYSIS.xlsm").Activate
Worksheets("Sheet3").Select
Range("A16:C16").Copy
Worksheets("Sheet4").Select
Range("B2").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Application.OnTime Now + TimeValue("00:00:01"), "test"
End Sub
The Sheet3.Select syntax isn't correct in VBA. Run-time error 1004 is common when you don't specify the range correctly or when an invalid name is used.
Related
I am getting an error Application defined or Object defined error when I run the below code. Error is highlighted at line Range("B2").End(xlDown).Offset(1, 0).Select
I even tried using Sheets("Sheet5").Range("B2").End(xlDown).Offset(1, 0).Select but it still gives the same error. Any help is much appreciated.
Worksheets("Sheet5").Select
Range("B2").End(xlDown).Offset(1, 0).Select
My full sub-
Sub test()
Workbooks("OC.xlsm").Activate
Worksheets("Sheet3").Select
Range("C13:E13").Copy
Worksheets("Live").Select
Range("B2").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Application.OnTime Now + TimeValue("00:00:10"), "test"
End Sub
I'm trying to copy from Sheet 1 (A1:C1) and paste a special value with offset and xlDown in Sheet 2 and place the respective results in Range (B3:D3).
Sheet 1
Sheet 4 - (Required output)
I'm getting a Run-time error '1004' Application-defined or object-defined error.
Sub test()
Workbooks("testing.xlsm").Activate
Sheet1.Select
Range("A1:C1").Copy
Sheet2.Select
Range("B3").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Application.OnTime Now + TimeValue("00:00:10"), "test"
End Sub
This should work:
Sub test()
Dim wsT As Worksheet
With Workbooks("testing.xlsm")
Set wsT = .Sheets("Sheet2")
wsT.Cells(wsT.Rows.Count, "B").End(xlUp).Offset(1, 0).Resize(1, 3).Value = _
.Sheets("Sheet1").Range("A1:C1").Value
Application.OnTime Now + TimeValue("00:00:10"), "test"
End With
End Sub
It's more efficient version of your code.
However, if you prefer to keep your style, this is less efficient version:
Sub test()
Workbooks("testing.xlsm").Activate
Sheet1.Select
Range("A1:C1").Copy
Sheet2.Select
Cells(Sheet2.Rows.Count, "B").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Application.OnTime Now + TimeValue("00:00:10"), "test"
End Sub
I am trying to run a paste value macro in a different sheet in a workbook that previously had a password protection.
The Macro works fine in the destination sheet for the values but not in the other tabs where i get this error runtime error '1004' - select method of range class failed
How should i proceed to allow this macro to run from a different active sheet?
Sub PasteSpecial_ValuesOnly()
Worksheets("ARF Table").Range("A2:AI13").Copy
'Error occurs below
**Worksheets("ARF Export").Range("A2:AI13").Select**
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Worksheets("ARF Export").Range("AK2").Value = Worksheets("ARF Export").Range("AD2").Value
End Sub
You only require the top left cell of the destination.
You don't need to .Select and direct value transfer is faster.
Sub PasteSpecial_ValuesOnly()
Worksheets("ARF Table").Range("A2:AI13").Copy
Worksheets("ARF Export").Range("A2").PasteSpecial Paste:=xlValues
Worksheets("ARF Export").Range("AK2").Value = Worksheets("ARF Export").Range("AD2").Value
End Sub
Alternate,
Sub PasteSpecial_ValuesOnly()
with Worksheets("ARF Table").Range("A2:AI13")
Worksheets("ARF Export").Range("A2").resize(.rows.count, .columns.count) = .value
end with
Worksheets("ARF Export").Range("AK2").Value = Worksheets("ARF Export").Range("AD2").Value
End Sub
So, I have a simple macro that just clears out specific cells. It worked fine, and then I added a userform that takes input via textbox and I added the last line TextBox1.Value= "" to clear it. Now, clicking the button that runs the macro works, it even clears the box, but then it gives me the 424 error. I'm sure its something basic I'm overlooking, syntax or some closing argument. Any help would be appreciated.
Sub Clear()
'
' Clear Macro
'
'
Range("A1").Select
Selection.ClearContents
Range("H17").Select
Selection.ClearContents
Range("H11").Select
Selection.ClearContents
Range("B1").Select
Selection.ClearContents
Range("I4").Select
Selection.ClearContents
Range("K4").Select
Selection.ClearContents
Range("M4").Select
Selection.ClearContents
Range("H10").Select
Selection.ClearContents
Range("H16").Select
Selection.ClearContents
TextBox1.Value = ""
End Sub
Sub notebutton1_Click()
Range("K8").Select
Selection.Copy
End Sub
Sub notebutton2_Click()
Range("K13").Select
Selection.Copy
End Sub
Sub notebutton3_Click()
Range("K18").Select
Selection.Copy
End Sub
TextBox1.Value = "" should be accompanied with the form it is living in. So for example Userform1.TextBox1.Value = ""
I've found a snippet for selecting the next empty row in excel, but when I run the macro it tells me that it throws a runtime error 1004. Any idea why?
Sub CopyValues()
Sheets("Report").Select
Range("B4:D10").Select
Selection.Copy
Sheets("Data").Select
Range("A1").End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
End Sub
And yes, the worksheet names are correct.
Range("A1").End(xlDown).Offset(1, 0).Select throws the error
Sub CopyValues()
Sheets("Report").Range("B4:D10").Copy _
Destination:=Sheets("Data").Range("A" & Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row + 1)
End Sub