开发者

Generate a string with specific values in a range of cells in Excel

开发者 https://www.devze.com 2023-01-29 11:05 出处:网络
For example, I have 4 cells in the worksheet \"data\" with some data like bellow ----------------------------

For example, I have 4 cells in the worksheet "data" with some data like bellow

 ----------------------------
 Param1|Param2|Param3|Param4|
 ----------------------------
 Value1|Value2|Value3|Value4|

And I put a button in this same workbook to generate a string with these values following this specific format (illustrative):

cmd.exe "-Value1-Value2-Value3-Value4-"

But I need to put this generated string in many cells in another worksheet according a specific conditions related with value in other cell, for example

-----------------------------------------------------
description | lorem ipsun lorem ipsun lorem ipsun lor|
------------------------------------------------------
command     | cmd.exe "-Value1-Value2-Value3-Value4-"|
------------------------------------------------------
description2| abra cadabra                           |
------------------------------------------------------
command     | cmd.exe "-Value1-Value2-Value3-Value4-"|
------------------------------------------------------

I need to put a generated string only in the lines that A1 cel开发者_运维技巧l has the value "command"

Could some one help with this issue contributing with some vba code? I'm not a lazy gui but I guess more simple and effective to ask in a specialized forum than try to found it in a mess websites, and for it's a challenge to solve this rapidly

Thanks so much


Here is some (non-working!) skeleton code to get you started:

Sub Fill_In_These_Cells

    Dim InsertThis as string
    InsertThis = _
        activeworksheet.range("Value1'sRange") & "-" & _
        activeworksheet.range("Value2'sRange") & "-" & _
        activeworksheet.range("Value3'sRange") & "-" & _
        activeworksheet.range("Value4'sRange")

    Dim OutputRange as string
    OutputRange= "A1:B4"
    Dim i as integer
    For i = 1 to 4
        if activeworksheet.cells(i,1).value="Command" then _
            activeworksheet.cells(i,2).value=InsertThis
    Next i
End Sub

I many not what to know the answer, but Why are you putting command lines into an Excel file in the first place? And why are you mixing them up with other text as well?

Edit

Somehow, I was awake enough to write psuedo-code this morning, but not enough to complete that sentence.

0

精彩评论

暂无评论...
验证码 换一张
取 消