#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"