在粘贴范围之间创建空白空间

时间:2018-08-28 15:25:31

标签: vba excel-vba

我正在做过滤器,然后将数据从工作簿复制/粘贴到其他工作簿。我能够处理过滤器并复制/粘贴。但是,如果产品代码具有两个以上的订单,我不知道如何创建空白空间。我附上图片以便于理解。 我的代码执行: enter image description here

我希望它转向: enter image description here

这是我的代码:

SELECT 
commission_sale_history.invoice_year, 
commission_sale_history.invoice_month, 
branch.branch_description, 
commission_reps.division, 
commission_reps.rep_name, 
commission_reps.employee_id, 
commission_sale_history.customer_id, 
customer.customer_name, 
commission_sale_history.invoice_no, 
commission_sale_history.order_no, 
commission_sale_history.product_division, 
commission_sale_history.commission_type, 
commission_sale_history.sales, 
commission_sale_history.commission_cost, 
commission_sale_history.commission_amount, 
commission_sale_history.payment_date, 
commission_sale_history.invoice_date,
commission_sale_history.commission_rate, 
commission_sale_history.commission_split,
commission_reps.salary

FROM ((((commission_sale_history WITH (NOLOCK)
INNER JOIN commission_reps WITH (NOLOCK)
ON (commission_sale_history.branch_id = commission_reps.branch_id) 
AND (commission_sale_history.rep_id = commission_reps.rep_id)) 
INNER JOIN customer WITH (NOLOCK)
ON commission_sale_history.customer_id = customer.customer_id) 
INNER JOIN branch WITH (NOLOCK)
ON commission_sale_history.branch_id = branch.branch_id) 
INNER JOIN ReportIDTable WITH (NOLOCK)
ON commission_reps.rep_id = 
CASE WHEN CONVERT(int,ReportIDTable.Salesrep) = 999999
THEN commission_reps.rep_id ELSE
CONVERT(int,ReportIDTable.Salesrep) END)
LEFT JOIN invoice_hdr_salesrep WITH (NOLOCK)
ON invoice_hdr_salesrep.invoice_number = commission_sale_history.invoice_no
AND invoice_hdr_salesrep.salesrep_id = commission_sale_history.rep_id

WHERE ReportIDTable.ReportID = 1 
AND ReportIDTable.UserID = @UserID
AND ((Branch IN (@BranchID)) OR Branch = '9999')


AND commission_sale_history.rep_id IN(@SalesRepID)
AND commission_sale_history.invoice_date >= @InvoiceStartDate
AND commission_sale_history.payment_date
BETWEEN @PaymentFromDate AND @PaymentThroughDate
AND commission_sale_history.paid_in_full_flag = 'Y'
AND ISNULL(commission_sale_history.credit_matched_to_payment_flag,'Y') = 'Y'
AND commission_sale_history.product_division 
NOT IN ('Parts Sales', 'Rental', 'Forklift/Equipment', 'Service')
AND ISNULL(invoice_hdr_salesrep.primary_salesrep,'Y')='Y'

ORDER BY
commission_reps.rep_name,
customer.customer_id, 
commission_sale_history.invoice_no,
commission_sale_history.commission_type

谢谢您的帮助:D

0 个答案:

没有答案