2015-08-15 107 views
1

我是使用vba代碼的初學者,我需要一個語句函數使其在第一列的行偏移量= 1048567時繼續處理時使其移動到具有新的開始單元格輸出的新列vba代碼Vba代碼if語句

If sq(lUser_1, 2) & "" <> sqq(lUser_2) Then 

    'we found a new combination, output to screen 
    Range(sStartingCellOutput).Offset(lRowOffset).Resize(, 3).Value = Array(sq(lUser_1, 2), sqq(lUser_2), rTopic.Value) 

    'increment the counter 
    lRowOffset = lRowOffset + 1 

End If 
+0

問題不清楚。 – Tarik

回答

2

您需要引入另一個變量來處理列偏移量。

dim lColOffset as long 
lColOffset = 0 
If sq(lUser_1, 2) & "" <> sqq(lUser_2) Then 

    'we found a new combination, output to screen 
    Range(sStartingCellOutput).Offset(lRowOffset, lColOffset).Resize(1, 3).Value = _ 
     Array(sq(lUser_1, 2), sqq(lUser_2), rTopic.Value) 

    'increment the counter 
    lRowOffset = lRowOffset + 1 
    if lRowOffset >= Rows.Count then 
     lRowOffset = 0 
     lColOffset = lColOffset + 4 
    end if 

End If 

我將列偏移量錯開了4.您將三個值放入行中,這樣會留下空白列。調整stag is是你的願望。

+0

非常感謝它的工作:D –

+0

[很高興聽到你快速解決](http://stackoverflow.com/help/someone-answers)。 – Jeeped

+0

對一個不清楚的問題的正確答案:+1 @FifoHsn - 請接受回答以關閉問題 –