2017-09-01 4 views
0

Excelファイル内の複数のシートから情報を取得しています。行のデータソースであるシートの名前をセルに埋め込みます。

その行の情報がどのシートから来ているかに基づいて列を記入したいと思います。例えば

シートB上のデータをシートA、SheetB.ColumnEの値(SourceSheet)から採取された場合、 "A" または "B" であるべきである

Private Sub Update_Click() 

Application.ScreenUpdating = False 
    Application.Calculation = xlCalculationManual 

    Dim path As String, fileName As String 
    Dim lastRowInput As Long, lastRowOutput As Long, rowCntr As Long, lastColumn As Long 
    Dim inputWS1 As Worksheet, outputWS As Worksheet 

    'set your sheets here 
    Set inputWS1 = ThisWorkbook.Sheets("Universal") 
    Set outputWS = ThisWorkbook.Sheets("Carriers") 
    rowCntr = 1 

    'get last rows from both sheets 
    lastRowInput = inputWS1.Cells(Rows.Count, "A").End(xlUp).Row 
    lastRowOutput = outputWS.Cells(Rows.Count, "A").End(xlUp).Row 
    lastColumn = inputWS1.Cells(1, Columns.Count).End(xlToLeft).Column 

    'copy data from columns A, B, E, G, I, J, L and M 
    inputWS1.Range("A4:A" & lastRowInput).Copy outputWS.Range("B2") 
    inputWS1.Range("B4:B" & lastRowInput).Copy outputWS.Range("C2") 


    Application.ScreenUpdating = True 
    Application.Calculation = xlCalculationAutomatic 
End Sub 

私の現在のコードでありますシートユニバーサルからシートキャリアに情報を引き出す。私はE列に「ユニバーサル」という言葉を置きたい。

私は複数のシートを行いますと、私は列に彼らに名前を提供するために、同じコードを使用することができます仮定E.

答えて

1
'copy data from columns A, B, E, G, I, J, L and M 
inputWS1.Range("A4:A" & lastRowInput).Copy outputWS.Range("B2") 
inputWS1.Range("B4:B" & lastRowInput).Copy outputWS.Range("C2") 

outputWS.Range("E2:E" & (lastRowInput-2)).Value = inputWS1.Name '<< add name 
+0

働いたこと!ありがとう! –