Соответствующий столбец Match

В Java 8 используйте файлы и пути и используя конструкцию try-with-resources.

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class WriteFile{
    public static void main(String[] args) throws IOException {
        String file = "text.txt";
        System.out.println("Writing to file: " + file);
        // Files.newBufferedWriter() uses UTF-8 encoding by default
        try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(file))) {
            writer.write("Java\n");
            writer.write("Python\n");
            writer.write("Clojure\n");
            writer.write("Scala\n");
            writer.write("JavaScript\n");
        } // the file will be automatically closed
    }
}
-1
задан sam 28 March 2019 в 14:40
поделиться

1 ответ

Что-то похожее на этот пример должно сработать для вас.

Sub CopyDest3()

Dim shtImp As Worksheet
Dim shtSrc As Worksheet
Dim wbs As Workbook
Dim wbd As Workbook
Dim k As Integer
Set wbd = ThisWorkbook
Set wbs = Workbooks("Source_1.xlsx") 'presuming workbook is open
Set shtImp = wbd.Sheets("Dest")
k = 1
For k = 1 To 2
Set shtSrc = wbs.Sheets(k)

'From Source to Dest
Dim rngImpTitles As Range
Set rngImpTitles = shtImp.Rows(1)
Dim rngImpNames As Range
Set rngImpNames = shtImp.Columns(1)

Dim CopyColumn As Long
Dim CopyRow As Long
Dim foundRow As Long
Dim foundCol As Long

On Error Resume Next
'for each column in row 1 of import sheet
For CopyColumn = 2 To shtSrc.Cells(1, shtSrc.Columns.count).End(xlToLeft).Column
    foundCol = rngImpTitles.Find(shtSrc.Cells(1, CopyColumn).Value2).Column
    If Err.Number <> 0 Then
        MsgBox "Not such a col title in importsheet for " & vbNewLine & _
                        shtSrc.Cells(1, CopyColumn)
        Err.Clear
        GoTo skip_title
    End If


    For CopyRow = 2 To shtSrc.Cells(shtSrc.Rows.count, 1).End(xlUp).Row
        foundRow = rngImpNames.Find(shtSrc.Cells(CopyRow, 1)).Row
        If Err.Number <> 0 Then
            MsgBox "Not such a row name in importsheet for " & vbNewLine & _
                        shtSrc.Cells(CopyRow, 1)
            Err.Clear
            GoTo skip_row
        End If

            If Len(shtSrc.Cells(CopyRow, CopyColumn)) <> 0 Then
                    shtSrc.Cells(CopyRow, CopyColumn).Copy shtImp.Cells(foundRow, foundCol)
            End If

skip_row:
    Next CopyRow
skip_title:
Next CopyColumn
Next k
End Sub
0
ответ дан skkakkar 28 March 2019 в 14:40
поделиться
Другие вопросы по тегам:

Похожие вопросы: