Input Data Macro but I can't sum 3 cells from Sheet 1 before submitting to a cell in Sheet 2

SomethingNew

New Member
Joined
Jul 2, 2024
Messages
4
Office Version
  1. 2016
  2. Prefer Not To Say
Platform
  1. Windows
  2. Web
I don't know why it's not working honestly, I assumed it was in case the cell has no value or is blank and that's why it won't run but I'm not sure.
Posting almost my whole script because I'm not sure if it's really the sumValue that is the problem or did I break a rule somewhere:

VBA Code:
sumValue = Range("CUSTOMS").Value + Range("LOCAL_CHARGES").Value + Range("EXPORT_COST").Value

next_row = Sheets(ws_output).Range("B" & Rows.Count).End(xlUp).Offset(1).Row

If IsEmpty(Range("DOLLAR").Value) Or Range("DOLLAR").Value = "" Then
    Sheets(ws_output).Cells(next_row, 31).Value = Range("PESO_COST").Value
Else
    Sheets(ws_output).Cells(next_row, 29).Value = Range("DOLLAR").Value
    Sheets(ws_output).Cells(next_row, 30).Value = Range("RATE").Value
End If


If IsEmpty(Range("DOLLAR").Value) Or Range("DOLLAR").Value = "" Then
    Sheets(ws_output).Cells(next_row, 35).Value = Range("PP_INPUT_VAT").Value
Else
    Sheets(ws_output).Cells(next_row, 35).Value = Range("CDT_INPUTVAT").Value
End If


Sheets(ws_output).Cells(next_row, 40).Value = Range("CHARGES_BROKER").Value
Sheets(ws_output).Cells(next_row, 41).Value = Range("CHARGES_INPUT").Value

Sheets(ws_output).Cells(next_row, 48).Value = sumValue


End Sub


The rest of the script is basically:

Sheets(ws_output).Cells(next_row, 1).Resize(NoOfRows).Value = Range("DESCRIPTION").Value
Dim sumValue As Double

or

Sheets(ws_output).Cells(next_row, 24).Value = Range("SITE").Value
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
It's not clear what you mean by "not working"?

The three relevant codelines are:

VBA Code:
sumvalue = Range("CUSTOMS").Value + Range("LOCAL_CHARGES").Value + Range("EXPORT_COST").Value

next_row = Sheets(ws_output).Range("B" & Rows.Count).End(xlUp).Offset(1).Row

Sheets(ws_output).Cells(next_row, 48).Value = sumvalue

Is the code writing anything to Sheets(ws_output).Cells(next_row, 48)? If not, then perhaps the code isn't getting to this line. Could it be branching earlier? or are you perhaps using an On Error Resume Next statement?

Or perhaps later code is overwriting what was written?

What do you mean by this? Is there code you're not showing us. Is it in this Sub? Or is there other code running?
The rest of the script is basically ...

I suggest you start by putting a breakpoint on this line:
Code:
Sheets(ws_output).Cells(next_row, 48).Value = sumvalue

Does the code execution get this far? Is this line writing the correct value?
 
Upvote 0
It's not clear what you mean by "not working"?

The three relevant codelines are:

VBA Code:
sumvalue = Range("CUSTOMS").Value + Range("LOCAL_CHARGES").Value + Range("EXPORT_COST").Value

next_row = Sheets(ws_output).Range("B" & Rows.Count).End(xlUp).Offset(1).Row

Sheets(ws_output).Cells(next_row, 48).Value = sumvalue

Is the code writing anything to Sheets(ws_output).Cells(next_row, 48)? If not, then perhaps the code isn't getting to this line. Could it be branching earlier? or are you perhaps using an On Error Resume Next statement?

Or perhaps later code is overwriting what was written?

What do you mean by this? Is there code you're not showing us. Is it in this Sub? Or is there other code running?


I suggest you start by putting a breakpoint on this line:
Code:
Sheets(ws_output).Cells(next_row, 48).Value = sumvalue

Does the code execution get this far? Is this line writing the correct value?
Hello, I'm sorry, I didn't mean to make my question vague.
Yes there is more code, it's just very basic and I felt a little embarrassed to share something so rudimentary.

1. The only time value is inputted in next row,48 is with the sumvalue which I tried to set as a value.
2. The error code says Mismatch which I'm not sure why as I only used Double


VBA Code:
ws_output = "SAMPLE FINAL"

Dim sumValue As Double
sumValue = Range("CUSTOMS").Value + Range("LOCAL_CHARGES").Value + Range("EXPORT_COST").Value


next_row = Sheets(ws_output).Range("B" & Rows.Count).End(xlUp).Offset(1).Row

Sheets(ws_output).Cells(next_row, 1).Resize(NoOfRows).Value = Range("DESCRIPTION").Value
Sheets(ws_output).Cells(next_row, 18).Resize(NoOfRows).Value = Range("QTY").Value
Sheets(ws_output).Cells(next_row, 19).Resize(NoOfRows).Value = Range("UOM").Value
Sheets(ws_output).Cells(next_row, 20).Resize(NoOfRows).Value = Range("ITEM").Value
Sheets(ws_output).Cells(next_row, 24).Value = Range("SITE").Value
Sheets(ws_output).Cells(next_row, 25).Value = Range("MODALITY").Value
Sheets(ws_output).Cells(next_row, 26).Value = Range("WEIGHT").Value
Sheets(ws_output).Cells(next_row, 27).Value = Range("DIMENSION").Value
Sheets(ws_output).Cells(next_row, 28).Value = Range("CANVASS_DATE").Value


If IsEmpty(Range("DOLLAR").Value) Or Range("DOLLAR").Value = "" Then
    Sheets(ws_output).Cells(next_row, 31).Value = Range("PESO_COST").Value
Else
    Sheets(ws_output).Cells(next_row, 29).Value = Range("DOLLAR").Value
    Sheets(ws_output).Cells(next_row, 30).Value = Range("RATE").Value
End If


'Sheets(ws_output).Cells(next_row, 28).Value = Range("ITEM_COST").Value (IF NO USD)
'Sheets(ws_output).Cells(next_row, 31).Value = Range("PESO_COST").Value (IF NO USD OTHERWISE FORMULA ALREADY)

If IsEmpty(Range("DOLLAR").Value) Or Range("DOLLAR").Value = "" Then
    Sheets(ws_output).Cells(next_row, 35).Value = Range("PP_INPUT_VAT").Value
Else
    Sheets(ws_output).Cells(next_row, 35).Value = Range("CDT_INPUTVAT").Value
End If


'Sheets(ws_output).Cells(next_row, 39).Value = Range("TOTAL_CDT").Value (FORMULA ALREADY)

Sheets(ws_output).Cells(next_row, 40).Value = Range("CHARGES_BROKER").Value
Sheets(ws_output).Cells(next_row, 41).Value = Range("CHARGES_INPUT").Value

'Sheets(ws_output).Cells(next_row, 40).Value = Range("DELIVERY").Value (only need the total)
'Sheets(ws_output).Cells(next_row, 40).Value = Range("RETURN_COST").Value (only need the total)
Sheets(ws_output).Cells(next_row, 48).Value = sumValue

End Sub

Thank you for taking a look at it and informing me about my lack of information, I do apologize for that.
 
Upvote 0
No need for apologies or embarrassment.

Which code line produces the error?

I'm guessing it's the second line here:

VBA Code:
Dim sumValue As Double
sumValue = Range("CUSTOMS").Value + Range("LOCAL_CHARGES").Value + Range("EXPORT_COST").Value

If so, this could mean that one or more of CUSTOMS, LOCAL_CHARGES and EXPORT_COST is an error value. Or a text value.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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