Calculations for ages

SLinas

New Member
Joined
Aug 10, 2018
Messages
6
Hey Guys,

I have kinda complicated UserForm and tried to do some tricks with one extra button, but as soon as I have created it and try to press it takes me ages it keeps saying "Calculating" for like one minute before transfering any data to the sheets. Maybe you guys have any idea which of the code lines makes this happen... Thanks in advance!

Code:
Private Sub CommandButton1_Click()

Dim emptyRow As Long




'Activates barcode sheet
Worksheets("barcode").Activate


'where the data will be transfered
emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1


If clicked = True Then
GoTo JustPrint


End If


'Data transfer


Cells(emptyRow, 2).Value = DateTextBox.Value
Cells(emptyRow, 3).Value = ClientTextBox.Value
Cells(emptyRow, 4).Value = ComboBox1.Value
Cells(emptyRow, 5).Value = TextBox1.Value


Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Cells(Rows.Count, "E").End(xlUp).Row
Range("A" & LastRow).Copy Destination:=Range("F1")
Range("A" & LastRow).Copy Destination:=Sheets("Stock").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Application.ScreenUpdating = True


With Sheets("barcodeprint")


.Range("A1").Value = ClientTextBox.Text
.Range("C4").Value = DateTextBox.Text
.Range("C5").Value = ComboBox1.Value
.Range("C6").Value = TextBox1.Value


'Print
JustPrint:
Sheets("barcodeprint").PrintOut


clicked = True


End With
    
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You asking Excel to Calculate when you're using CountA to get the emptyRow, if it's taking a while then maybe it's because there is a lot of data there?

I made a few changes to your code, I changed the way you find the last row to a VBA function and switched off Calculation see if this helps any?

Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim emptyRow As Long

'Activates barcode sheet
Worksheets("barcode").Activate

'where the data will be transfered
emptyRow = Range("A" & Rows.Count).End(xlUp).Row + 1

If clicked = True Then GoTo JustPrint

'Data transfer
Cells(emptyRow, 2).Value = DateTextBox.Value
Cells(emptyRow, 3).Value = ClientTextBox.Value
Cells(emptyRow, 4).Value = ComboBox1.Value
Cells(emptyRow, 5).Value = TextBox1.Value

Dim LastRow As Long
LastRow = Cells(Rows.Count, "E").End(xlUp).Row
Range("A" & LastRow).Copy Destination:=Range("F1")
Range("A" & LastRow).Copy Destination:=Sheets("Stock").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)

With Sheets("barcodeprint")
    .Range("A1").Value = ClientTextBox.Text
    .Range("C4").Value = DateTextBox.Text
    .Range("C5").Value = ComboBox1.Value
    .Range("C6").Value = TextBox1.Value
End With

'Print
JustPrint:
Sheets("barcodeprint").PrintOut
clicked = True

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
You asking Excel to Calculate when you're using CountA to get the emptyRow, if it's taking a while then maybe it's because there is a lot of data there?

I made a few changes to your code, I changed the way you find the last row to a VBA function and switched off Calculation see if this helps any?

Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim emptyRow As Long

'Activates barcode sheet
Worksheets("barcode").Activate

'where the data will be transfered
emptyRow = Range("A" & Rows.Count).End(xlUp).Row + 1

If clicked = True Then GoTo JustPrint

'Data transfer
Cells(emptyRow, 2).Value = DateTextBox.Value
Cells(emptyRow, 3).Value = ClientTextBox.Value
Cells(emptyRow, 4).Value = ComboBox1.Value
Cells(emptyRow, 5).Value = TextBox1.Value

Dim LastRow As Long
LastRow = Cells(Rows.Count, "E").End(xlUp).Row
Range("A" & LastRow).Copy Destination:=Range("F1")
Range("A" & LastRow).Copy Destination:=Sheets("Stock").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)

With Sheets("barcodeprint")
    .Range("A1").Value = ClientTextBox.Text
    .Range("C4").Value = DateTextBox.Text
    .Range("C5").Value = ComboBox1.Value
    .Range("C6").Value = TextBox1.Value
End With

'Print
JustPrint:
Sheets("barcodeprint").PrintOut
clicked = True

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
    
End Sub

Thank you very much, Manual calculation sorted out everything. Thanks again, saved my day!
Code:
[COLOR=#333333]Application.Calculation = xlCalculationAutomatic[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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