Data not copying to register

Jnb99

Board Regular
Joined
Mar 29, 2016
Messages
85
Hi everyone,

I've compiled code which worked fine until this morning when I added the part to copy the main cells of the quote sheet to a Quote register.

What I am trying to achieve when macro is run is: Save active quote sheet as a new sheet with quote number as sheet name (WORKING), save a PDF copy with quote number as pdf file name (WORKING), copy main data from quote to register (NOT WORKING), Clear contents (WORKING).

Error info:
Run time error '1004'
Method 'range' of object '_worksheet' failed
Code in bold below is highlighted yellow

Thanks in advance

EDIT: Code is not showed as bold. I've added a comment

Code:

VBA Code:
Private Sub CommandButton1_Click()
 
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Set WS1 = Worksheets("Estimate")
Set WS2 = Worksheets("EDatabase")
' Figure out which row is next row
NextRow = WS2.Cells(Rows.Count, 1).End(xlUp).Row + 1
'Write the important values to register
[B]WS2.Cells(NextRow, 1).Resize(1, 5).Value = Array(WS1.Range("F4"), WS1.Range("F3"), WS1.Range("A14"), Range("EstTot"))[/B]                     'THIS IS THE ERROR

End Sub
 
Sub saveAsPdf()
Dim saveLocation As String
    Dim rng As Range
    saveLocation = "C:\Users\***\Estimates\" & Range("f4").Value & Range("a14").Value & ".pdf"
   
    Set rng = Worksheets("Estimate").Range("A1:g50")
    rng.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveLocation
   
    Call saveSheetWithoutFormulas
   
End Sub
Sub saveSheetWithoutFormulas()
    Dim ws As Worksheet
'f4 is document number
    Set wh = Worksheets(ActiveSheet.Name)
    ActiveSheet.Copy After:=Worksheets(Sheets.Count)
    If wh.Range("f4").Value <> "" Then
    ActiveSheet.Name = wh.Range("f4").Value
    End If
    wh.Activate
With Sheets("Estimate").Range("f4")
     .Value = "E" & (Mid(.Value, 2) + 1)
End With
 Call clearContents
End Sub

Sub clearContents()
Range("a23:d43").clearContents
Range("f23:f43").clearContents
Range("a14").clearContents

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi,
try this update to your line of code & see if resolves the issue

VBA Code:
WS2.Cells(NextRow, 1).Resize(, 4).Value = Array(WS1.Range("F4").Value, WS1.Range("F3").Value _
                                               , WS1.Range("A14").Value, WS1.Range("EstTot").Value)

Dave
 
Upvote 0
Solution
Hi,
try this update to your line of code & see if resolves the issue

VBA Code:
WS2.Cells(NextRow, 1).Resize(, 4).Value = Array(WS1.Range("F4").Value, WS1.Range("F3").Value _
                                               , WS1.Range("A14").Value, WS1.Range("EstTot").Value)

Dave
Hi Dave, nope same error
 
Upvote 0
Do you have another workbook open when running the code?

Dave
 
Upvote 0
Check the Name Manger & that the named range matches.

Rich (BB code):
WS1.Range("EstTot")

Dave
 
Upvote 0
Lol. How in the world did you know that. I did change it, but for some reason it changed back to G43. Ok now it is copying data, but the rest of the code is not working?
 
Upvote 0
I did not, just process of elimination - pleased you found resolution to rest of your issues

Dave
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,341
Members
452,638
Latest member
Oluwabukunmi

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