Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88075

Excel VBA Applying Vlookup formula to next empty column

$
0
0
Sub GET_BHAV()

Dim FinalWs As Worksheet, dataWs As Worksheet
Dim FinalLastRow As Long, dataLastRow As Long, x As Long
Dim dataRng As Range

Set FinalWs = ThisWorkbook.Worksheets("Open")

Workbooks.Open "D:\NITIN\PROSTOCK\NSE_REPORTS\cm07JAN2020.csv"

Set dataWs = Workbooks("cm07JAN2020.csv").Worksheets("cm07JAN2020")

dataLastRow = dataWs.Range("A"& Rows.Count).End(xlUp).Row
FinalLastRow = FinalWs.Range("A"& Rows.Count).End(xlUp).Row

Set dataRng = dataWs.Range("A2:G"& dataLastRow)

For x = 2 To FinalLastRow



    On Error Resume Next

        'pasteSheet.Cells(2, Rows.Count).End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteFormulas
        'FinalWs.Cells(2, Columns.Count).End(xlToLeft).Offset(0, 1).Value = Application.WorksheetFunction.VLookup( _

        FinalWs.Cells(2, Columns.Count).End(xlToLeft).Offset(0, 1).Value = Application.WorksheetFunction.VLookup( _
        FinalWs.Range("A"& x).Value, dataRng, 4, False)



        '[IF I USE THE CODES BELOW, IT APPLIES THE FORMULA TO A PARTICLULAR COLUMN]
        'FinalWs.Range("HR"& x).Value = Application.WorksheetFunction.VLookup( _
        'FinalWs.Range("A"& x).Value, dataRng, 4, False)


Next x

End Sub

With these VBA codes, I am trying to fetch the data from one workbook to another workbook using Vlookup.

What I need is to get the values in next empty column from 1st row to last available lookup. I am getting the values in next empty column but the values are being going on in a single row to right side instead of moving down to same column.

I would be very grateful if anyone could help me.


Viewing all articles
Browse latest Browse all 88075

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>