Excel VBA粘贴到活动单元的偏移量

时间:2019-01-03 09:13:42

标签: excel vba excel-vba

我在UserForm中有一个代码,用于将粘贴值从一个工作表复制到活动单元格中。

我想将粘贴复制到活动单元格偏移中。偏移粘贴的像元位于左侧1个像元,向上10个像元。

1)将L67从工作表“其他数据”复制到活动单元格中

2)将工作表“其他数据”中的Q67复制到活动单元格偏移量(-1,-10)

我尝试过的代码:

Private Sub CommandButton2_Click()

'Paste to a Defined Range
ThisWorkbook.Sheets("Other Data").Range("L67").Copy

'Offset Paste (offsets 2 cells down and 1 to the right
ActiveCell.PasteSpecial xlPasteValues

ThisWorkbook.Sheets("Other Data").Range("Q67").Copy
ActiveCell.Offset(-1, -10).PasteSpecial xlPasteValues

End Sub

我收到以下错误消息:

ActiveCell.Offset(-1, -10).PasteSpecial xlPasteValues

1 个答案:

答案 0 :(得分:3)

您获得的偏移量方向错误。第一个数字是行,第二个数字是列,因此它将是:

#include <immintrin.h>

int main()
{
    const __m256i compareConstant = _mm256_setr_epi8( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
        13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 );

    long start = clock();
    char name[ 32 ] = "abcdefghijklmnopqrstuvwxyz";
    // __m256i is a C name for AVX register.
    // AVX registers are 32 bytes in size, so your 26 bytes string fits in just a single one.
    // The following line loads your string from memory to that register.
    __m256i n = _mm256_loadu_si256( ( const __m256i* )name );
    for( int i = 0; i < 100000000; i++ )
    {
        // Increment the letters, all 32 of them.
        // `_mm256_set1_epi8` creates a value with all 32 bytes set to the same value.
        // `_mm256_add_epi8` adds one set of 32 signed bytes to another set of 32 signed bytes.
        // It's not a loop i.e. it's very fast, CPUs can actually run 2-3 such instructions per cycle. 
        __m256i n2 = _mm256_add_epi8( n, _mm256_set1_epi8( 1 ) );

        // Wrap any > 'z' letters back to 'a'
        // _mm256_cmpgt_epi8 compares one set of bytes to another set, for `>`.
        // When it's `>` the result byte is set to 0xFF, when it's `<=` the result byte is 0.
        // _mm256_blendv_epi8 combines bytes from 2 registers based on the bytes from the third one.
        // In this case, the third one is the result of the comparison.
        n2 = _mm256_blendv_epi8( n2, _mm256_set1_epi8( 'a' ), _mm256_cmpgt_epi8( n2, _mm256_set1_epi8( 'z' ) ) );

        // Combine incremented ones with old, using random number of first characters
        const int r = rand() % 25;
        // This sets all 32 bytes in rv to the random number r
        __m256i rv = _mm256_broadcastb_epi8( _mm_cvtsi32_si128( r ) );
        // Compares all bytes in rv with the constant value [0, 1, 2, 3, ...]
        // For bytes where r>cc, blendv_epi8 will select a byte from n2.
        // For bytes where r<=cc, n will not change because blendv_epi8 will select an old value.
        n = _mm256_blendv_epi8( n, n2, _mm256_cmpgt_epi8( rv, compareConstant ) );
    }
    long stop = clock();
    printf( "time taken = %ld sec \n", ( stop - start ) / 1000 );
}