G
G
GoUp2015-08-21 12:30:51
contextual advertising
GoUp, 2015-08-21 12:30:51

How to transfer individual data from one Excel sheet to another?

Sheet 1 has a column with 1000 words. Of these, 500 words contain a specific word, such as chair. How to cut these words from this sheet and transfer to sheet 2? On sheet 1, these words are deleted.
Is there such a function or macro?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Fedoryan, 2015-08-21
@GoUp

On the "Developer" panel there is a button "Record macro":
- click on it;
- do the necessary procedures (moving / deleting words);
- stop recording;
- see the resulting code;
- remove the excess. add what you need.
It is not entirely clear how the words will be programmatically selected?
UpD ( here's what I got ):

Private Sub CommandButton1_Click()
    Dim key_word As String ' ключевое слово, по которому будем отбирать
    Dim i, count As Integer
        
    key_word = TextBox1.Text
    Sheets("Лист1").Select
    count = 0
    i = 1
    While (Cells(i, 1) <> "") ' проходим до первой пустой ячейки столбец А '
        If (InStr(1, LCase(Cells(i, 1)), LCase(key_word), vbBinaryCompare) > 0) Then ' если совпало '
            count = count + 1
            Cells(i, 1).Select
            Selection.Cut ' вырезаем из Лист1 '
            Sheets("Лист2").Select
            Cells(count, 1).Select
            ActiveSheet.Paste ' вставляем в Лист2 '
            Sheets("Лист1").Select
        End If
        i = i + 1
    Wend
    Label1.Caption = "find: " & count
    
    i = i - 1
    While (i > 0)
        If (Cells(i, 1) = "") Then
            Cells(i, 1).Select
            Selection.Delete Shift:=xlUp ' в Лист1 удаляем все пустые ячейки со сдвигом вверх '
        End If
        i = i - 1
    Wend
End Sub

882aadf50b174301ae0b53c9a257fffd.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question