Check for data in every other column of a range.

stirlingmw1

Board Regular
Joined
Jun 17, 2016
Messages
53
Office Version
  1. 2016
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
Afternoon all

I hope I explain this right.

I have a worksheet that contains data from multiple shops and imported into the workbook to the worksheet "ImportData". This data then copied from "ImportData" into every other column of the worksheet "Main" using following code. The first 3 columns of the "Main" worksheet have "ID number", "category" and "item description" for multiple items, there are then 2 blank columns followed by the data from "importData" into every other column. This data is the qty of each item listed in the 1st 3 columns that is available across multiple stores with each store name in the first row of each imported column.

VBA Code:
Sub AddDataToMain()

Dim ImpLRow As Long, MLRow As Long, i As Long
Dim wsI As Worksheet, wsM As Worksheet
Dim Ary As Variant

Set wsM = Worksheets("Main")
Set wsI = Worksheets("ImportData")

'Adds NSN ADAC and Description to Main page
ImpLRow = wsI.cells(Rows.Count, 1).End(xlUp).Row
MLRow = wsM.cells(Rows.Count, 1).End(xlUp).Row
Ary = wsI.Range("A4:BE" & ImpLRow).Value2

wsM.Range("A4:C" & ImpLRow).Value = Application.Index(Ary, Evaluate("row(1:" & ImpLRow - 3 & ")"), Array(1, 2, 3))
For i = 4 To UBound(Ary, 2)
   wsM.Range("E4:E" & ImpLRow).Offset(, (i - 3) * 2 - 1).Value = Application.Index(Ary, , i)
Next i


End Sub

The data is added as mentioned into every other column from F to BE leaving the blank column for me to annotate an qty of the items that I require to be moved from the store listed in the first row to another. I am trying to put some code together that if I have annotated a qty in any of the cells the blank columns the code copies the "ID number", "category" and "item description" into the first 3 columns of worksheet "Supplied_from" followed by the Qty I have annotated and then the Store Name from the top of the column which the Qty is annotated in, the code should loop through all of the rows from row 4 to Lastrow and copy data each time it encounters a Qty in one of the blank columns. If there are multiple Qtys in a row all Qtys and Store names should be annotated in the "Supplied_from" worksheet.

I know this is a big ask but hope you can help.

regards

Steve
 

Attachments

  • Tracker.png
    Tracker.png
    119.8 KB · Views: 11
  • Supplied_from.png
    Supplied_from.png
    92.6 KB · Views: 13

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Could you post a small sample of your Main sheet.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Could you post a small sample of your Main sheet.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
Store Uplift Tracker.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBF
1UNITBookers BBookers ABookers BLundiLiptonChidngfoldCLYDEHelensburghROOKEGRIMSBYHURWORTHLEDBURYMERSEYMIDDLETONPEMBROKEPENZANCERAMSEYSEVERNSHOREHAMTYNEWarehouseWiltonFORTHMEDWAYTRENTSPEYTAMAR
2N4171AN4107AN0855AN0853AN0859AN0890AN8210AN5380HN8314AN0861AN0852AN0889AN0856AN8313AN7417AN4109AN0929AN4170AN0887AMINOR WARSHIPSN5314GN0930AN0931AN0932AN0934AN0933ATotal
3ID NumberCategoryItem DescriptionQty RequiredQty AchievedQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty HeldQty NeededQty
41305-20-000709511203-07Potatoes 2316390539797338538018374580059515164680
51305-99-812523011909-05Carrots 900002000595022459435945935555939648
61305-99-740396911921-02Apples 0576444601469937060858969994569378645026524518411296380564010004615477
71305-99-602161612007-07Oranges50050013718295200010017695754410059931006994198112149346431011817695159946895077204995271906985100919752463933124192499
81305-99-347032812449-02Grapes 2942930096295978
91310-99-676512112461-01Mince 0434454252834101321729
101305-99-384414612463-02Beetroot 1941854484691452441061842931350255322598565354552302
111370-12-367617213804-01Tea 1094115
121375-99-248420350404-02Coffee10105206464205324230000101
131375-99-382404050603-05Sugar 14019352328019234240019177547
141375-99-588067051004-01Yogurt - Plain 2046
151375-99-577164451010-11Flour221011100110322000112
161375-99-152556351301-09Mint 002021232001114
179920-99-665424351403-02Matches 110210206200015
181370-99-962796313030-02BBQ Bricketts 0
191305-19-003505712202-02Pork 18151483941001510153445823504534015021002781
201370-12-375134742030-01Beef 0212111019
211340-12-382748112712-01Lamb 790301010570101610806106430011221310207
221305-99-958607211916-02Lettuce 001010
231305-99-327811712015-27Onion 20008130100099500994317213751775160711256
241375-99-488972352418-01Tyme 00100103200108
Main
Cell Formulas
RangeFormula
E4:E24E4=IF(SUM(G4,I4,K4,M4,O4,Q4,S4,U4,W4,Y4,AA4,AC4,AE4,AG4,AI4,AK4,AM4,AO4,AQ4,AS4,AU4,AW4,AY4,BA4,BC4,BE4)=0,"",SUM(G4,I4,K4,M4,O4,Q4,S4,U4,W4,Y4,AA4,AC4,AE4,AG4,AI4,AK4,AM4,AO4,AQ4,AS4,AU4,AW4,AY4,BA4,BC4,BE4))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E4:E40Expression=$E4<$D4textNO
F3:BE3Cell Value<>""""""textNO
D4:E40Expression=AND($D4=$E4,$D4>0)textNO
A4:BF40Expression=CELL("row")=ROW()textNO
A4:BF40Expression=$A4<>""textNO
A4:BF40Expression=$A4=""textNO
A4:C40Cell Value=""textNO
A4:C40Cell Value<>""textNO
Cells with Data Validation
CellAllowCriteria
C1List=Units
 
Upvote 0
Thanks for that, how about
VBA Code:
Sub stirlingmw()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long, nc As Long
   Dim Flg As Boolean
   
   With Sheets("Main")
      Ary = .Range("A1:BE" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
   End With
   ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2))
   nc = 2
   For r = 4 To UBound(Ary)
      For c = 7 To UBound(Ary, 2) Step 2
         If Ary(r, c) <> "" Then
            If Not Flg Then nr = nr + 1
            Flg = True
            nc = nc + 2
            Nary(nr, 1) = Ary(r, 1)
            Nary(nr, 2) = Ary(r, 2)
            Nary(nr, 3) = Ary(r, 3)
            Nary(nr, nc) = Ary(1, c - 1)
            Nary(nr, nc + 1) = Ary(r, c)
         End If
      Next c
      Flg = False
      nc = 2
   Next r
   Sheets("Supplied_from").Range("A2").Resize(nr, UBound(Nary, 2)).Value = Nary
End Sub
 
Upvote 0
Solution
Thanks for that, how about
VBA Code:
Sub stirlingmw()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long, nc As Long
   Dim Flg As Boolean
  
   With Sheets("Main")
      Ary = .Range("A1:BE" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
   End With
   ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2))
   nc = 2
   For r = 4 To UBound(Ary)
      For c = 7 To UBound(Ary, 2) Step 2
         If Ary(r, c) <> "" Then
            If Not Flg Then nr = nr + 1
            Flg = True
            nc = nc + 2
            Nary(nr, 1) = Ary(r, 1)
            Nary(nr, 2) = Ary(r, 2)
            Nary(nr, 3) = Ary(r, 3)
            Nary(nr, nc) = Ary(1, c - 1)
            Nary(nr, nc + 1) = Ary(r, c)
         End If
      Next c
      Flg = False
      nc = 2
   Next r
   Sheets("Supplied_from").Range("A2").Resize(nr, UBound(Nary, 2)).Value = Nary
End Sub
Fluff

Thank you, works exactly as I wanted. Your skills never stop impressing.

Regards

Stevee
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,693
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top