Копировать и передавать данные из одного столбца в другой столбец - PullRequest
0 голосов
/ 09 июня 2018

Я хочу сначала найти ячейку банка в столбце G, а затем выбрать ячейку в том же столбце F. Затем выбрать данные из этой ячейки для последней заполненной ячейки и скопировать.затем снова зайдите в пустую ячейку столбца G и вставьте значения.Пожалуйста, помогите мне.

Sub copyy2()
    Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
    Dim currentRowValue As String
    Dim A As Long
    Dim otherCol As Integer
    Dim cell As Excel.Range    
    sourceCol = 8   'column H has a value of 8
    otherCol = sourceCol - 1    'column before H
    rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
    'for every row, find the first blank cell and select it
    With Sheets("sheet1")
    For currentRow = 1 To rowCount
        currentRowValue = Cells(currentRow, sourceCol).Value
        If IsEmpty(currentRowValue) Or currentRowValue = "" Then
        A = currentRow
            'cell = Cells(currentRow, sourceCol)
            Exit For
  End If
    Next  
    'A = cell.Row    
    Cells(A, otherCol).Select         
    Range(Selection, Cells(A, otherCol).End(xlDown)).Select
    Selection.copy
    Range(Selection, Cells(A, sourceCol)).Select
    End With        
End Sub

1 Ответ

0 голосов
/ 09 июня 2018

Попробуй,

dim rng as range
With Sheets("sheet1")
    set rng = .columns("G").specialcells(xlcelltypeblanks).cells(1)
    if .cells(.rows.count, "F").end(xlup).row > rng.row then
        .range(rng.offset(0, -1), .cells(.rows.count, "F").end(xlup)).copy _
           destination:=rng
    end if
end with
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...