Simple Loop Question

sharksandwich

New Member
Joined
Jan 4, 2010
Messages
9
Hello to those that take the time to read this and thank you.

I am not asking for anyone to do my homework only I have not been able to find a solution so far.

Scenario: I need a macro/VBA to look in a range of about 20 cells. The cells have an if statement that pulls data from a cell according to date. Some have a value and some have an if function that equals zero. All I am trying to do is keep the value of the cells that have the function greater than zero and not convert value of the if function cells that end up with a zero.

I have a small VBA script to change a cell range to value:
<TABLE style="WIDTH: 234pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=312><COLGROUP><COL style="WIDTH: 234pt; mso-width-source: userset; mso-width-alt: 11410" width=312><TBODY><TR style="HEIGHT: 15.75pt" height=21><TD style="BORDER-BOTTOM: #e0dfe3; BORDER-LEFT: #e0dfe3; BACKGROUND-COLOR: transparent; WIDTH: 234pt; HEIGHT: 15.75pt; BORDER-TOP: #e0dfe3; BORDER-RIGHT: #e0dfe3" class=xl63 height=21 width=312>Sub Values_3()

</TD></TR><TR style="HEIGHT: 15.75pt" height=21><TD style="BORDER-BOTTOM: #e0dfe3; BORDER-LEFT: #e0dfe3; BACKGROUND-COLOR: transparent; HEIGHT: 15.75pt; BORDER-TOP: #e0dfe3; BORDER-RIGHT: #e0dfe3" class=xl63 height=21>Range("A1:D1").Value = Range("A1:D1").Value</TD></TR><TR style="HEIGHT: 15.75pt" height=21><TD style="BORDER-BOTTOM: #e0dfe3; BORDER-LEFT: #e0dfe3; BACKGROUND-COLOR: transparent; HEIGHT: 15.75pt; BORDER-TOP: #e0dfe3; BORDER-RIGHT: #e0dfe3" class=xl63 height=21>End Sub

I am looking to turn it into a loop that will end if the value is zero while converting existing data or greater than 0 data to value only within in the range.

Any suggestions?
Thanks in advance.

</TD></TR></TBODY></TABLE>
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
not sure exactly what u are asking but this will loop through the used range within the workshop change the 'do something with code u want to perform
Code:
Sub t()
Dim rng As Range

For Each rng In ActiveSheet.UsedRange
    If rng.Value > 0 Then
        'do something
    End If
Next

    
End Sub
 
Upvote 0
Thanks for the quick response. I ran the macro and it turned them all into a value. I was trying to avoid turning the cells with the value of zero into a static value and keep the function in the cell until it has a value greater than zero. Sounds so simple but I am limited and learning daily.

Here is how I put it together, maybe I did it wrong?


Sub t()
Dim rng As Range
For Each rng In ActiveSheet.UsedRange
If rng.Value > 0 Then
Range("A6:D6").Value = Range("A6:D6").Value
End If
Next

End Sub
 
Upvote 0
Found the answer:

Sub R()
Dim rng As Range
For i = 1 To 24
If (Sheet1.Cells(1, 1) = Sheet3.Cells(1, i)) Then
Sheet3.Cells(5, i) = Sheet2.Cells(2, 1)
End If
Next
End Sub


_______________
thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,172
Members
449,071
Latest member
cdnMech

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