Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

For Each Cell in Sheet1 Range, do some Vlookup calc. from Sheet3

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
u473 - 24 May 2008 00:07 GMT
I need help in switching back & forth from sheet to sheet and using
VlookUp
& Match to retrieve values at the intersect of current Row & Column.
.
For Each Cell in Sheet1 Range, do some Vlookup calculations from
Sheet3
and write results in Sheet2 same relative range.

Assume Range in Sheet1 is  B2:D3 as follows :
Row / Col       A           B           C       D
   1          Position    RateA    RateB  RateC ....
   2          Manager    10          8        12
   3          Cost Engr.   6         16         6
   4          ..............    ..          ..         ..
Assume RateTable in Sheet3 is  B2:D.. as follows :
Row / Col       A           B           C       D
   1          Position    RateA    RateB  RateC ....
   2          Manager    50          55        60
   3          Cost Engr. 35          40        45
   4          ..............   ..            ..         ..
For each Cell in Sheet1 range which contains Hours at specific Rate
Code,
Vlookup/Match RateTable in Sheet3 for  pertaining Position,
and write Hours multiplied by Rate in Sheet2 in same relative position
as in Sheet1
as follows :
Row / Col       A           B           C       D
   1          Position    RateA    RateB  RateC ....
   2          Manager    500        440     720
   3          Cost Engr. 210        640     270
------ Pseudo Code ------------------------
Sub Test()
Dim rng As Range
Dim RateCat As String ' Rate Category, RateA, RateB, RateC etc...
Dim Rate As Integer : Dim LastRow as Integer
Dim Position as String
LastRow = Cells(Rows.Count,"A").End(xlUp).Row
Set rng = Range("B2:D" & LastRow): Range("B2").Select
For Each Cell In rng
  'Vlookup/Match  Position and RateCat from Sheet3 and store value in
Rate
  ' Multiply Sheet1.ActiveCell.Value  with Rate and store result in
Sheet3,
  'same relative Row/Column
ActiveCell.Offset(0, 1).Select
Next Cell
End Sub

Help appreciated,
Celeste
merjet - 24 May 2008 02:57 GMT
The solution looks easy to me, and doesn't require VBA. Merely enter
formulas on Sheet2 that use values from Sheet1 and Sheet3, e.g. for
Sheet2, cell B2: =Sheet1!B2*Sheet3!B2

Hth,
Merjet
u473 - 24 May 2008 03:58 GMT
Thank you for your answer, but I want to find the solution in VBA for
further complex cases..
Celeste
Joel - 24 May 2008 04:26 GMT
Sub Test()
Dim rng As Range
Dim RateCat As String ' Rate Category, RateA, RateB, RateC etc...
Dim Rate As Integer: Dim LastRow As Integer
Dim Position As String

With Sheets("Sheet1")
  LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
  For RowCount = 2 To LastRow
     Position = .Range("A" & RowCount)
     With Sheets("Sheet3")
        Set c = .Columns("A").Find(what:=Position, _
           LookIn:=xlValues, lookat:=xlWhole)
        If Not c Is Nothing Then
           c.EntireRow.Copy Destination:=Sheets("Sheet2").Row(RowCount)
        End If
     End With
  Next RowCount
End With
End Su

> Thank you for your answer, but I want to find the solution in VBA for
> further complex cases..
> Celeste
Gary Keramidas - 24 May 2008 05:12 GMT
give this a try and report back any issues:

Sub test()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim lastrow As Long
Dim lastcol As Long
Dim i As Long, z As Long
Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range
Dim rngfound As Range
     Set ws1 = Worksheets("Sheet1")
     lastrow = ws1.Cells(Rows.Count, "A").End(xlUp).Row
     lastcol = ws1.Cells(1, Columns.Count).End(xlToLeft).Column
     Set ws2 = Worksheets("Sheet2")
     Set ws3 = Worksheets("Sheet3")
     z = 2
     ws2.Activate
     'Application.ScreenUpdating = False

     For i = 2 To lastrow
           With ws3.Columns("A:A")
                 Set rngfound = .Find(ws1.Range("A" & i).Value, _
                     lookat:=xlWhole)
                 If Not rngfound Is Nothing Then
                       ws2.Range("A" & z).Value = .Range("A" & i).Value
                       ws1.Range(Cells(i, "B").Address, Cells(i, _
                           lastcol).Address).Copy
                       ws2.Range("B" & z).PasteSpecial xlPasteAll
                       ws3.Range(Cells(rngfound.Row, "B").Address, _
                           Cells(rngfound.Row, lastcol).Address).Copy
                       ws2.Range("B" & z).PasteSpecial xlPasteAll, _
                           xlPasteSpecialOperationMultiply
                       z = z + 1
                 End If
           End With
     Next
     Application.CutCopyMode = False
End Sub

Signature

Gary

>I need help in switching back & forth from sheet to sheet and using
> VlookUp
[quoted text clipped - 46 lines]
> Help appreciated,
> Celeste
u473 - 24 May 2008 13:31 GMT
Thank you a thousand times. You made my day.
Those 2 examples just put me back on track of logic and syntax.
Have a good day, from Williamsburg Virginia.
Celeste
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.