Dave Smith
New Member
- Joined
- Jul 5, 2021
- Messages
- 32
- Office Version
- 2016
- Platform
- Windows
Hi Experts,
I am not getting proper idea of getting values in multiple rows with single cell value using vba (vba script) also i have encountered the Error "1004" while writing my program.
I have 3 sheets having name as "Sheet1","Sheet2","Sheet3"
In the sheet 1 in column it contains various "Q1, Q2,.......................,Q15" while in the row it contains value like "Inven_01 etc".
Same as "sheet1", "sheet2" also contains same values.
Now in the "sheet3" in the Range "B5" if some enters the Inven_01 then cells adjacent to Q1 to Q15 respective value should be come (while the value for Q1, Inven_01 lies in the sheet 1)
If anybody help me to sort out this it will be very helpful
I am not getting proper idea of getting values in multiple rows with single cell value using vba (vba script) also i have encountered the Error "1004" while writing my program.
I have 3 sheets having name as "Sheet1","Sheet2","Sheet3"
In the sheet 1 in column it contains various "Q1, Q2,.......................,Q15" while in the row it contains value like "Inven_01 etc".
Same as "sheet1", "sheet2" also contains same values.
Now in the "sheet3" in the Range "B5" if some enters the Inven_01 then cells adjacent to Q1 to Q15 respective value should be come (while the value for Q1, Inven_01 lies in the sheet 1)
VBA Code:
Dim myLookupValue As String
Dim myFirstColumn As Long
Dim myLastColumn As Long
Dim myColumnIndex As Long
Dim myFirstRow As Long
Dim myLastRow As Long
Dim myVLookupResult As Long
Dim myTableArray As Range
myLookupValue = Worksheets("Sheet3").Range("B5")
myFirstColumn = 2
myLastColumn = 3
myColumnIndex = 2
myFirstRow = 6
myLastRow = 305
With Worksheets("Sheet1")
Set myTableArray = .Range(.Cells(myFirstRow, myFirstColumn), .Cells(myLastRow, myLastColumn))
End With
myVLookupResult = WorksheetFunction.VLookup(myLookupValue, myTableArray, myColumnIndex, False)
Worksheets("Sheet1").Range("B9") = myVLookupResult
End Sub
If anybody help me to sort out this it will be very helpful