Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
If and?
I have two worksheets in a workbook. I want to populate some columns in
sheet1 from data in sheet2 based on data in both sheets. There are a lot more records in sheet1 then sheet2. For example Sheet1: RSE BM EM N O P 01K4 0 2.5 01K4 2.5 5 01K13 0 1.2 01K13 1.2 3.2 01K23 0 1.7 01K23 1.7 2.2 01K23 2.2 3.6 Sheet2: RSE B C D E 01K4 3.2 01K13 1 01K23 1.3 01K23 2.7 I need some code that will look at Sheet 2 row by row and if the RSE value is equal to Sheet 1's RSE value and Sheet 2's B value is between or equal to Sheet 1's BM and EM value, then the values in columns C, D, and E from Sheet 2 get pasted in to the coresponding N, O, and P columns in Sheet 1. I was thinking a loop with some sort of if statement might work? thank you |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
If and?
Assume that RSE is in column 1
BM - column 2 EM - column 3 B - column 2 Using the 7 rows of your sheet1 and the 4 rows of your sheet2: Sub test() Dim i As Integer Dim j As Integer Dim k As Integer Dim mID As String For i = 1 To 7 mID = Sheets("Sheet1").Cells(i, 1) For j = 1 To 4 If mID = Sheets("Sheet2").Cells(j, 1) Then If Sheets("Sheet2").Cells(j, 2) = Sheets("Sheet1").Cells(i, 2) _ And Sheets("Sheet2").Cells(j, 2) <= Sheets("Sheet1").Cells(i, 3) Then For k = 3 To 5 Sheets("Sheet1").Cells(i, k + 11) = Sheets("Sheet2").Cells(j, k) Next End If End If Next j Next i End Sub "Knox" wrote: I have two worksheets in a workbook. I want to populate some columns in sheet1 from data in sheet2 based on data in both sheets. There are a lot more records in sheet1 then sheet2. For example Sheet1: RSE BM EM N O P 01K4 0 2.5 01K4 2.5 5 01K13 0 1.2 01K13 1.2 3.2 01K23 0 1.7 01K23 1.7 2.2 01K23 2.2 3.6 Sheet2: RSE B C D E 01K4 3.2 01K13 1 01K23 1.3 01K23 2.7 I need some code that will look at Sheet 2 row by row and if the RSE value is equal to Sheet 1's RSE value and Sheet 2's B value is between or equal to Sheet 1's BM and EM value, then the values in columns C, D, and E from Sheet 2 get pasted in to the coresponding N, O, and P columns in Sheet 1. I was thinking a loop with some sort of if statement might work? thank you |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|