Using VBA to transfer data

rohlo1be

New Member
Joined
Sep 7, 2022
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hello all,

New to the forum so if there is a thread I can read that is already established, happy to view it. However, I am attempting to use VBA to send code from a submission spreadsheet to another log of the data.

Currently the code works, however, it is copying the formulas and not just the values as I have calculated fields in my submission spread sheet.

Here is the current code:

Private Sub CommandButton1_Click()
'assigns each sheet to a variable
Dim rvucalc As Worksheet
Dim prodsum As Worksheet

Set rvucalc = Sheet7
Set prodsum = Sheet1

'selects and copies all the variables in RVU calculator
Dim year As Range

Dim month As Range
Dim facility As Range
Dim discipline As Range
Dim therapist As Range
Dim amount As Range
Dim timetotal As Range
Dim untimetotal As Range
Dim rvutotal As Range

Set year = rvucalc.Range("C4")
Set month = rvucalc.Range("E4")
Set facility = rvucalc.Range("C5")
Set discipline = rvucalc.Range("G5")
Set therapist = rvucalc.Range("E5")
Set amount = rvucalc.Range("C24")
Set timetotal = rvucalc.Range("D24")
Set untimetotal = rvucalc.Range("E24")
Set rvutotal = rvucalc.Range("F24")
'Set the destination cell
Dim DestCell As Range

If prodsum.Range("A2") = "" Then 'If A2 is empty
Set DestCell = prodsum.Range("A2") '...then destination cell is A2
Else
Set DestCell = prodsum.Range("A1").End(xlDown).Offset(1, 0) '...otherwise the next empty row
End If

year.Copy DestCell
month.Copy DestCell.Offset(0, 1)
facility.Copy DestCell.Offset(0, 2)
discipline.Copy DestCell.Offset(0, 3)
therapist.Copy DestCell.Offset(0, 4)
amount.Copy DestCell.Offset(0, 5)
timetotal.Copy DestCell.Offset(0, 6)
untimetotal.Copy DestCell.Offset(0, 7)
rvutotal.Copy DestCell.Offset(0, 8)

MsgBox "Are you sure the data is correct?", vbYesNoCancel, ["Data Confirmation"]

rvucalc.Range("B7:C23").ClearContents
rvucalc.Range("E5").ClearContents


MsgBox "Form is ready for another submission", vbOKOnly, ["Submission Complete"]

End Sub


I would appreciated any help.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
If you just want values then change the lines from this format:
VBA Code:
Month.Copy DestCell.Offset(0, 1)

To this format
VBA Code:
    Month.Copy
    DestCell.Offset(0, 1).PasteSpecial Paste:=xlPasteValues
    ' OR
    DestCell.Offset(0, 1).Value = Month.Value

    ' If you want to keep the number formatting use this instead
    Month.Copy
    DestCell.Offset(0, 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats

    ' If you want to keep all the formatting
    Month.Copy
    DestCell.Offset(0, 1).PasteSpecial Paste:=xlPasteValues
    DestCell.Offset(0, 1).PasteSpecial Paste:=xlPasteFormats
 
Upvote 0
If you just want values then change the lines from this format:
VBA Code:
Month.Copy DestCell.Offset(0, 1)

To this format
VBA Code:
    Month.Copy
    DestCell.Offset(0, 1).PasteSpecial Paste:=xlPasteValues
    ' OR
    DestCell.Offset(0, 1).Value = Month.Value

    ' If you want to keep the number formatting use this instead
    Month.Copy
    DestCell.Offset(0, 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats

    ' If you want to keep all the formatting
    Month.Copy
    DestCell.Offset(0, 1).PasteSpecial Paste:=xlPasteValues
    DestCell.Offset(0, 1).PasteSpecial Paste:=xlPasteFormats
Thank you, That worked!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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