Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k views
in Technique[技术] by (71.8m points)

vba - Insert rows based on two or more conditions in Excel

I'm currently working for a company that collects data from public ilumination systems around my country. We use a lot of Excel Sheets to organize data and, because of that, we end up using a bunch of formulas to speed up the process. However, I'm new to VBA and I need some help with a code that I was trying to create.

This is what I'm trying to make

Each row has an ID, and each ID has a sequence of multiple types of lamps (sodium vapor) and power in watts (I need to copy this sequence from another sheet). I need to pick this values and put in the main table, if there are 2 lamps that are equal in both power and type, I need to put the type+power in the "Lamp" column, and the number of times it appears in the row (2) in the "Quantity" column. BUT, if, in the same row, there are lamps with different powers or types, the other type of lamp needs to be inserted below the first row with the same ID. For example:

This is what should happen

I need to do this manually. I want to know if theres a way to make a VBA code that will check the number of repetitions of a specific value and return THE value and THE NUMBER OF REPETITIONS both in the "Quantity" column and in "Lamp" column, and IF THERE ARE DIFFERENT TYPES OF LAMPS will insert the necessary number of rows below the first one, containing the same data but the "Quantity" and "Lamp" values, these two should be the values of the second type of lamp and etc. Can you guys help me?

I'm sorry, english is not my main language and I'm still learning it, and I'm also bad at explananing so if you didn't get what I need I can clarify if necessary.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...