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
 
Is there a way to assign a hyperlink or quick link to the estimate database document numbers, to click on and open applicable sheet saved?
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Is there a way to assign a hyperlink or quick link to the estimate database document numbers, to click on and open applicable sheet saved?

different question - best start new thread.

Dave
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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