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>
 

tfaulkes

Board Regular
Joined
Jun 4, 2009
Messages
74
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
 

sharksandwich

New Member
Joined
Jan 4, 2010
Messages
9
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
 

sharksandwich

New Member
Joined
Jan 4, 2010
Messages
9
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!
 

Forum statistics

Threads
1,081,702
Messages
5,360,738
Members
400,594
Latest member
Frothingslosh

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top