Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I've been working on a macro for a few days now and I've gotten to
part that is over my head. I'm trying to code the following: For Each cell in Column G that has data in it (Calling this G# below) - If Cell(G#) = (Condition1 AND Condition2) OR (Condition3 AN Condition4) THEN --- Select all remaining cells in worksheet (including current row except those cells in Column A --- Multiply the numbers in all selected cells by ratio o Cell(G#)/Cell(G#-1) - Else Continue Next Cell (G#+1) - End If So far, I've figured out how to code the part about "selecting al remaining cells in the worksheet except those cells in column A" wit the following code: Range(Selection, Selection.End(xlToLeft)).Offset(0, 1).Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Can anyone offer any clues about how the rest of this is coded in vba? Thank -- Message posted from http://www.ExcelForum.com |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm not sure what those conditions are, but maybe this'll get you started:
Option Explicit Sub testme01() Dim myCell As Range Dim myRng As Range Dim myBlankCell As Range Dim wks As Worksheet Dim LastCell As Range Dim dummyRng As Range Set wks = Worksheets("sheet1") With wks Set dummyRng = .UsedRange 'try to reset lastused cell Set LastCell = .Cells.SpecialCells(xlCellTypeLastCell) Set myRng = .Range("g2", .Cells(.Rows.Count, "G").End(xlUp)) For Each myCell In myRng.Cells With myCell 'some conditions here that I don't understand If IsNumeric(.Value) Then If IsNumeric(.Offset(-1, 0).Value) Then If .Offset(-1, 0).Value < 0 Then LastCell.Offset(1, 1).Value _ = .Value / .Offset(-1, 0).Value Exit For End If End If End If End With Next myCell If IsEmpty(LastCell.Offset(1, 1)) Then 'do nothing, it didn't get populated with that ratio Else LastCell.Offset(1, 1).Copy .Range(.Cells(myCell.Row, "B"), LastCell).PasteSpecial _ Paste:=xlPasteAll, Operation:=xlMultiply, _ SkipBlanks:=False, Transpose:=False LastCell.ClearContents Set dummyRng = .UsedRange End If End With End Sub "Temp12 <" wrote: I've been working on a macro for a few days now and I've gotten to a part that is over my head. I'm trying to code the following: For Each cell in Column G that has data in it (Calling this G# below) - If Cell(G#) = (Condition1 AND Condition2) OR (Condition3 AND Condition4) THEN --- Select all remaining cells in worksheet (including current row) except those cells in Column A --- Multiply the numbers in all selected cells by ratio of Cell(G#)/Cell(G#-1) - Else Continue Next Cell (G#+1) - End If So far, I've figured out how to code the part about "selecting all remaining cells in the worksheet except those cells in column A" with the following code: Range(Selection, Selection.End(xlToLeft)).Offset(0, 1).Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Can anyone offer any clues about how the rest of this is coded in vba? Thanks --- Message posted from http://www.ExcelForum.com/ -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dave ... I probably didn't give enough information in my first post, s
the code didn't quite work. However, your post gave me several goo ideas about how to do this and now I have a macro that I think will d what I need. Thanks again for the help.. -- Message posted from http://www.ExcelForum.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
code question | Excel Discussion (Misc queries) | |||
vb code question | Excel Discussion (Misc queries) | |||
vb code question | Excel Discussion (Misc queries) | |||
VBA code question | Excel Discussion (Misc queries) | |||
Code Question | Excel Programming |