循环内的VBA循环

时间:2016-02-08 16:57:57

标签: excel vba

我目前正在寻找这个数据

说我有

4行 第一个始终开始 A列中的UO2 下面将是S72(即UO2的原因) 我需要做的是为我们目前的S72s提供参考 将s72链接到uo2的唯一方法是知道s72直接位于u02之下,直到下一个uo2

我需要做的是复制s72所涉及的每一行的UO2条目,然后将s72移位,以便我没有重复

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <h1>Item 1</h1>
  <h1>Item 2</h1>
  <h1>Item 3</h1>
</div>
<select style='display: none;'></select>

我需要宏做的是

    function onPhotoURISuccess(imageURI) {
     var largeImage = document.getElementById('smallImage');
    largeImage.style.display = 'block';
    largeImage.src = imageURI;
    basestrg = encodeImageUri(imageURI);

}

function getPhoto(source) {
           navigator.camera.getPicture(onPhotoURISuccess, onFail, {
        destinationType: Camera.DestinationType.NATIVE_URI, mediaType: Camera.MediaType.Photo,
        sourceType: source
    });
}
function encodeImageUri(imageUri) {
    var c = document.createElement('canvas');
    var ctx = c.getContext("2d");
    var img = new Image();
    img.onload = function () {
        c.width = this.width;
        c.height = this.height;
        ctx.drawImage(img, 0, 0);
    };
    img.src = imageUri;
    var dataURL = c.toDataURL("image/jpeg");
    return dataURL;
}

s72可能有多种原因,唯一的停止参考就是另一个UO2的退出

1 个答案:

答案 0 :(得分:0)

如果我理解,您基本上希望将A列变成仅用于UO2的列,并将S72数据从2(?)列移到C列。

如果那是对的,你只需要两个Long变量来控制你的循环,一个用于当前行的查看,另一个用作UO2的参考。例如:

Dim i as Long
Dim j as Long

'Start them at the same point, assumes row 1 is header
i = 2
j = 2

'Assuming that once Column A is blank, we have no more data to process
Do While Range("A" & i).value <> ""
    'Check for UO2
    If Range("A" & i).value = "UO2" 'Adjust condition appropriately
        'Update j
        j = i
    Else
        'Shift the data over (If there is data to the right of Column C already you'll
        ' need to tweak this code to not overwrite it
        Range("C" & i).value = Range("B" & i).value

        'Copy down the UO2 info
        Range("A" & i).value = Range("A" & j).value
        Range("B" & i).value = Range("B" & j).value
    End if

    'Increment i no matter the case
    i = i + 1
Loop

'You then need to loop through and delete the rows that have only UO2 data (i.e. Column C
' would be blank), but that shouldn't be too difficult