如何使用VBA将后缀添加到excel中的特定数据

时间:2015-11-30 06:27:43

标签: excel vba excel-vba

我维护了一个包含特定产品参数的工作表。

当我点击ADD按钮时,控制电源变压器的所有内容都应该被复制,并且应该粘贴在下面。

在这里,我成功地使用下面提到的vba代码复制整个产品详细信息并粘贴到下面:

Dim WbEPC As Workbook, _
WbCPT As Workbook, _
WsEPC As Worksheet, _
WsCPT As Worksheet, _
FirstAddress As String, _
WriteRow As Long, _
cF As Range, _
num As String

Set WbEPC = Workbooks("EPC 1.xlsm")
Set WbCPT = Workbooks("Control Power Transformers.xlsm")
Set WsEPC = WbEPC.Sheets("Sheet1")
Set WsCPT = WbCPT.Sheets("Sheet1")


Dim b As Object, RowNumber As Integer
Set b = ActiveSheet.Shapes("CommandButton21")
With b.TopLeftCell
    RowNumber = .Row
End With


 Rows(RowNumber + 1 & ":" & RowNumber + 1).Select
 Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

With WsEPC
.Activate
With .Range("A1:A10000")

Set cF = .Find(what:="CTPT", _
    lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)

            num = cF.Address

            WsEPC.Range(cF.Offset(-1, 0), cF.Offset(3, 3).End(xlDown)).Copy

            WsEPC.Range("A" & RowNumber + 1).Select


                Selection.Insert Shift:=xlDown
                Application.CutCopyMode = False

    End With
 End With

 MsgBox " Successfully added the product to EPC"

以上代码成功复制了以下产品详情,如下所示

enter image description here

这里“CTPT1”是产品CONTROL POWER TRANSFORMERS的唯一产品ID,当我点击ADD时,同样的ID正在复制,而不是复制CTPT1,如图所示(A22)我想让它自动进入单击“添加”按钮时出现“CTPT2”,如果再次单击“添加”按钮,它将变为“CTPT3”,依此类推。

任何人都可以告诉我如何使用excel VBA实现这种自动生成唯一ID。感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="seller-facilitator@someDomain.com">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="item_name" value="Trex hide">
    <input id="PayPalPrice1" type="hidden" name="amount" value="">
    <button name="submit" class="btn btn-lg btn-success "> Checkout With <b> PayPal </b> </button>
</form>