Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Copy between workbooks if statement is true
I have two workbooks: Prisliste.xls (price list) and faktura.xls (invoice).
In the invoice I want to just write id-numbers, and based on these id-numbers, I want a macro to get the data from the price list. In Prisliste.xls I have the following data: Column A: id-number Column B: name of book Column D: price of book Column E: price of book ex. taxes In faktura.xls I have an area (cell B19 to D32), where I want the data transferred. Names of books in column B, prices in column D. I want to write id-numbers in the cells of column B, run a macro that replaces the numbers with names, and inserts the prices. How do I make the macro understand where to put the names and the prices? What should I write instead of ActiveSheet.Range("B") ? This is my code so far (I might be far off, or close to the solution): Sub boknummer() 'nameing the area in use "tittel" Dim tittel As Range Set tittel = Range("B19:B32") For Each Cell In tittel If Cell.Value = Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("A2").Value Then 'checks if the id-number is the same as the first id-number of Prisliste.xls ActiveSheet.Range("B") = Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("B2").Value 'inserts the book name ActiveSheet.Range("D") = Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("D2").Value 'inserts the book price End If 'checks the next id-number If Cell.Value = Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("A3").Value Then ActiveSheet.Range("B") = Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("B3").Value ActiveSheet.Range("D") = Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("E3").Value End If 'checks the other id-numbers, I excluded the code since it is similar to the examples above. Next End Sub Thanks for any suggestions, links etc Ingeborg Altern Vedal |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
TRUE/FALSE STATEMENT | Excel Discussion (Misc queries) | |||
copy an entire row IF a statement is true | Excel Worksheet Functions | |||
Two TRUE to one FALSE statement | Excel Worksheet Functions | |||
If then statement with two true conditions | Excel Programming | |||
if statement is true, copy data to another location | Excel Programming |