Excel vba or formula to Look for non zero in excel sheet row

Muhammad Hussaan

New Member
Joined
Dec 13, 2017
Messages
49
Office Version
  1. 2013
Platform
  1. Windows
Hello,
I need help to avoid alot of manual work and error.
I have sheet with width of material in row 4 column C to AV and possible cut patterns in row 5 to 103 in column C to AV having values of 0 to 5. I want the width against non zeros and number of times if it is greater than 1. As in Row 5 only two values are greater than ZERO in range C:5 to AV5 and values are 1 and 2 in cell V5 and Z5 respectively and againts these cells in row 4 we have 56 and 60. 56 has 1 in row 5 and 60 has 2 in row 5 therefore i write it as 56 |60 |60 columns AZ to BF manually.
How to to it by some formula or vba macro?
Kindly help.
Thanks
 

Attachments

  • IMG_20200418_124948.jpg
    IMG_20200418_124948.jpg
    180.7 KB · Views: 7
  • IMG_20200418_125006.jpg
    IMG_20200418_125006.jpg
    155.4 KB · Views: 9
  • IMG_20200418_124800.jpg
    IMG_20200418_124800.jpg
    199 KB · Views: 7

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
To get better & quicker answers I suggest ..
  1. Update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
  2. Investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.
  3. Provide small sample data that still demonstrates your issue. For example we didn't need to see 30 columns of this to get the idea (though you could still tell us that there are about 30 columns)
If you have the CONCAT function (if your version was shown in your profile I would know if you have the function) you could try this for a formula approach. The formula in H5 is copied across as far as you might need and down.

20 04 18.xlsm
BCDEFGHIJKLMNOP
48081828384
51201080818183     
60500281818181818484  
Non zero columns
Cell Formulas
RangeFormula
H5:P6H5=IFERROR(TRIM(MID(CONCAT(REPT(REPT(" ",100)&$B$4:$F$4,$B5:$F5)),COLUMNS($H:H)*100,100))+0,"")
 
Upvote 0
To get better & quicker answers I suggest ..
  1. Update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
  2. Investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.
  3. Provide small sample data that still demonstrates your issue. For example we didn't need to see 30 columns of this to get the idea (though you could still tell us that there are about 30 columns)
If you have the CONCAT function (if your version was shown in your profile I would know if you have the function) you could try this for a formula approach. The formula in H5 is copied across as far as you might need and down.

20 04 18.xlsm
BCDEFGHIJKLMNOP
48081828384
51201080818183     
60500281818181818484  
Non zero columns
Cell Formulas
RangeFormula
H5:P6H5=IFERROR(TRIM(MID(CONCAT(REPT(REPT(" ",100)&$B$4:$F$4,$B5:$F5)),COLUMNS($H:H)*100,100))+0,"")

Thanks i will try this.
I will follow the instructions also.
I have excel 2013.
 
Last edited by a moderator:
Upvote 0
I have excel 2013.
Please add it to your profile as suggested.


i will try this.
No need to, it will not work for you - because you have Excel 2013 (why you need it in your profile ;)).

Provided row 4 is ever-increasing as in your sample, you could try this instead.

20 04 18.xlsm
BCDEFGHIJKLMNOP
480818282.590
51201080818182.5     
60500281818181819090  
Non zero columns (2)
Cell Formulas
RangeFormula
H5:P6H5=IF(COLUMNS($H:H)>SUM($B5:$F5),"",INDEX($B$4:$F$4,IFERROR(MATCH(COLUMNS($H5:H5)-1,SUMIF($B$4:$F$4,"<="&$B$4:$F$4,$B5:$F5)),0)+1))
 
Upvote 0
If you wanted to consider a vba approach, then you could try this user-defined function.
To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy across and down.

VBA Code:
Function Seq(rHdrs As Range, rCount As Range, Num As Long) As Variant
  Dim a As Variant, d As Variant
  Dim i As Long, j As Long, k As Long
  
  a = rHdrs.Value
  d = rCount.Value
  Seq = vbNullString
  For i = 1 To UBound(d, 2)
    For j = 1 To d(1, i)
      k = k + 1
      If k = Num Then Seq = a(1, i)
    Next j
  Next i
End Function

Muhammad Hussaan 2020-04-18 1.xlsm
BCDEFGHIJKLMNOP
480818282.590
51201080818182.5     
60500281818181819090  
Non zero columns (3)
Cell Formulas
RangeFormula
H5:P6H5=Seq($B$4:$F$4,$B5:$F5,COLUMNS($H:H))
 
Upvote 0
If you wanted to consider a vba approach, then you could try this user-defined function.
To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy across and down.

VBA Code:
Function Seq(rHdrs As Range, rCount As Range, Num As Long) As Variant
  Dim a As Variant, d As Variant
  Dim i As Long, j As Long, k As Long
  
  a = rHdrs.Value
  d = rCount.Value
  Seq = vbNullString
  For i = 1 To UBound(d, 2)
    For j = 1 To d(1, i)
      k = k + 1
      If k = Num Then Seq = a(1, i)
    Next j
  Next i
End Function

Muhammad Hussaan 2020-04-18 1.xlsm
BCDEFGHIJKLMNOP
480818282.590
51201080818182.5     
60500281818181819090  
Non zero columns (3)
Cell Formulas
RangeFormula
H5:P6H5=Seq($B$4:$F$4,$B5:$F5,COLUMNS($H:H))
Dear Peter,
Thanks alot, vba code working perfectly.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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