Home > Software engineering >  Vba great god to see
Vba great god to see

Time:09-17

Try to weave a development ticket, a piece of up to 116000, so the inside of the amount to open several zhang, are required to keep tonnage within three decimal places, such as 116000/4480 (settled)=25.892 [XXX (he took three decimal places) and then back to calculate 25.892 * 4480=115996.16 (this is to make out an invoice amount)] the open amount to nearly 116000 but not more than the number and so on, and then to another new list, another must reflect [name of substance specifications unit quantity (25.892) and settlement unit price (4480) corresponding to the amount (115996.16)] VBA small white, you can do is to know that, the quantity is big trouble, thanks for the great god,

CodePudding user response:

Have "idea", according to your idea to write code for bai,


The "three decimal places", can set the cell formatting to show,
The "actual value" in the cell suggest or retain its original value, so at the time of "statistical", "error" will be reduced,

CodePudding user response:

Problem is to write don't come, small white a completely, now in the study, hope there is a example to learn and study

CodePudding user response:

Can directly use the formula...

CodePudding user response:

Please call me lei feng!
Open the macro dialog box, create a new name for the test macro, and then click edit, enter the following code:
 Sub test () 
Sheet2. Cells (1, 1)="material name"
Sheet2. Cells (1, 2)="specifications"
Sheet2. Cells (1, 3)="unit", "
Sheet2. Cells (1, 4)="number"
Sheet2. Cells (1, 5)="settlement price
"Sheet2. Cells (1, 6)="corresponding amount
"
Dim As Integer I
I=2

While Sheet1. Cells (I, 1) & lt;> "
"Dim j As Integer
For j=1 To 7
If j & lt; 4 Then=
Sheet2. Cells (I, j)=Sheet1. Cells (I, j)
ElseIf j=7 Then
Sheet2. Cells (I, 5)=Sheet1. Cells (I, j)
End the If
Next

If Sheet1. Cells (I, 8) & gt; Then 116000
Sheet2. Cells (I, 4)=Fix (116000/Sheet2. Cells (I, 5) * 1000)/1000
Sheet2. Cells (I, 6)=Sheet2. Cells (I, 4) * Sheet2. Cells (I, 5)
The Else
Sheet2. Cells (I, 6)=Sheet1. Cells (I, 8)
End the If

I=I + 1
Wend
End Sub

Excel spreadsheet download address:
https://download.csdn.net/download/milaoshu1020/10763168

CodePudding user response:

You can take a look at this I tried the
Option Explicit

Sub automatically generated receipt ()

Dim w As Worksheet
Dim w1 As Worksheet
Dim j As Integer
Dim As Integer I
Dim As Integer k
Dim x As Integer
Dim x1 As Double
Dim x2 As Double
K=2

Set w=Worksheets (" table ")
Sheets. The Add (before:=Sheets (" table ")). The Name="receipt"
The Set w1=Worksheets (" receipt ")

W1. Cells (1, 1)=w.C ells (1, 1)
W1. Cells (1, 2)=w.C ells (1, 2)
W1. Cells (1, 3)=w.C ells (1, 3)
W1. Cells (1, 4)=w.C ells (1, 4)
W1. Cells (1, 5)=w.C ells (1, 7)
W1. Cells (1, 6)=w.C ells (1, 8)

For j=2 To w.U sedRange. Rows. Count Step 1

X=Round (w.C ells (j, 8) 116000 +/0.5, 0)
If x & gt; 1 Then

For I=1 To Step 1 x - 1

X1=Round (116000/w.C ells (j, 7), 3) - 0.001
(x1 x2=Round * w.C ells (j, 7), 2)

W1. Cells (k, 1)=w.C ells (j, 1)
W1. Cells (k, 2)=w.C ells (j, 2)
W1. Cells (k, 3)=w.C ells (j, 3)
W1. Cells (k, 4)=x1
W1. Cells (k, 5)=w.C ells (j, 7)
W1. Cells (k, 6)=x2
K=k + 1
X=x - 1

If x=1 Then
W1. Cells (k, 1)=w.C ells (j, 1)
W1. Cells (k, 2)=w.C ells (j, 2)
W1. Cells (k, 3)=w.C ells (j, 3)
W1. Cells (k, 4)=w.C ells (j, 4) - (Round (116000/w.C ells (j, 7), 3) - 0.001) * (Round (w.C ells (j, 8) 116000 +/0.5, 0) - 1)
W1. Cells (k, 5)=w.C ells (j, 7)
W1. Cells (k, 6)=w.C ells (j, 8) - Round (x1 * w.C ells (j, 7), 2) * (Round (w.C ells (j, 8) 116000 +/0.5, 0) - 1)
K=k + 1
End the If
Next I
End the If
Next j
End Sub

CodePudding user response:



The original poster is missing, but also to dig the grave...
  •  Tags:  
  • VBA
  • Related