Copy data to a new sheet if cell contains a value

I am looking for help with a macro so I can easily sort and see data.

I have a spreadsheet with rows 1 and 2 containing item information. Rows 3-93 have the ordering information. For every row in 3-93, if there is a value in any column in between F and VU, copy the the corresponding value in columns A,B,C for that row to a new sheet called Orders and copy the corresponding values in rows 1 and 2 for that column.

for example, I need this:

......A..........B...........C...................................F...........................................GU

1..................................................100235410 (Navy Shirt)......101028 316 (Moss FR Plaid)

2..................................................................XL.........................................2XL T

3..Jack....Brown...Current.............................2..............................................1

Copied over to a new sheet called Orders, like this:

.......A.........B.............C.......................................D................................E..................F

1...Jack...Brown....Current..............100235410 (Navy Shirt).................XL.................2

2...Jack...Brown....Current............101028 316 (Moss FR Plaid).........2XL T..............1

I am struggling with the VBA logic and can't seem to get it work right. Any help or advise is greatly appreciated.

Thanks!

Answers


A problem like this can be a challenge to get your head around if you just dive into the coding especially for beginners it requires the definition of bite sized chunks that can be coded as descrete processes. I suggest you create a flow chart or step-by-step procedure that describes what you would do if you had to make the changes by hand. If your procedure accurately describes those steps, you can then create code that does each of the individual steps and string those code snips together in the order you described in your flow chart.

Also, be sure to define processes that can be repeated for each row or sheet or other descrete data set you will work with. You can then loop these processes to avoid writing the same code over and over again.

For your example above, if I understand correctly, you will first want to define the range in which customers are defined: in this case the range from A3 to A93 (or whatever the highest row number might be. If that varies, you'll want to define a range that changes with the particular data set (using the .End method, for example, if there are no empty cells in the data (ideally there should not be) you could do this:

Dim wbOrders As Workbook
    Set wbOrders = ActiveWorkbook
Dim wsOrders As Worksheet
    Set wsOrders = wbOrders.ActiveSheet
Dim rngOrders As Range
    Set rngOrders = wsOrders.Range("A3", wsOrders.Range("A3").End(xlDown))

Once you have defined the range in which orders are found, you can loop through the data to work with the individual orders:

Dim rngCustomer As Range

For Each rngCustomer In rngOrders
    '~~>Here you could define other ranges to work with (perhaps columns F to VU of the
    '   current row)
    '~~>Here you could also define other loops/routines to move the data
Next rngCustomer

Inside the above loop structure you could Dim a range of customer orders, loop through the range finding columns that contain data, use each column with found data (one at a time) to get the data(probably one cell at a time) from that row and rows 1 and 2, transfering it either onto either a new sheet, OR into an array of values that can be added to all new sheets after the first loop finds and defines all the customer order data and puts it in the array.

I hope this gives you enough to start tackling the problem. If you hit snags during the coding of an individual step, search around on StackOverflow or the web in general to find the solutions. If you don't find them, post a question that details what you've tried and includes the specific non-working code to StackOverflow and I almost guarantee you'll have an answer in 24 hours or less.


Need Your Help

Is it safe to integrate MVVM [angularjs,knockout.js]in MVC [JSF/spring]

angularjs jsf java-ee model-view-controller mvvm

Is it good practice to combine MVVM [angularjs,knockout.js]with MVC [JSF/spring].

iOS method call

ios

I have these two methods. How do I call them?