Home |
Search |
Today's Posts |
|
#1
![]() |
|||
|
|||
![]()
Even if you insert more than one row, this just adds 110 to the value in that
original cell. Option Explicit Sub Macro99() Dim numRows As Long Dim iRow As Long Dim LastRow As Long Dim FirstRow As Long numRows = Application.InputBox("How many Rows", Type:=1) If numRows < 1 Then Exit Sub Application.ScreenUpdating = False With ActiveSheet FirstRow = 5 '<-- LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row For iRow = LastRow To FirstRow Step -1 .Rows(iRow + 1).Resize(numRows).Insert .Rows(iRow).Copy _ Destination:=.Rows(iRow + 1).Resize(numRows) If IsNumeric(.Cells(iRow, "D").Value) Then .Cells(iRow + 1, "D").Resize(numRows).Value _ = .Cells(iRow, "D").Value + 110 End If 'On Error Resume Next '.Rows(iRow + ).Resize(numRows) '.Cells.SpecialCells(xlCellTypeConstants).ClearCon tents 'On Error GoTo 0 Next iRow End With Application.ScreenUpdating = True End Sub sloanranger wrote: i will only ever need to insert one row so d11=233 is correct Lee Sloan -- Dave Peterson |
#2
![]() |
|||
|
|||
![]()
Works a treat, thanks very much
Lee Sloan |
#3
![]() |
|||
|
|||
![]()
I have one more request,
i need to expand on the macro you wrote, this time can you make it turn column X into a colour based on a number in column W the colours i need are red, blue, yellow and green and the are determined by the numbers 4,3,2 and 1 respectively. example X5=35mv X6=70ml X7=35ml X8=70mv dont worry about what X contain, but they must stay (they are the result of a formula) and W5=4 W6=3 W7=2 W8=1 therefore X5 colorindex should be red, X6 should be blue, X7 should be yellow and X8 should be green and all this needs to be applied before the insert and copy loop starts Hope you can help Lee Sloan |
#4
![]() |
|||
|
|||
![]()
Just the new rows?
You'll have to record a macro to find the colors you want to use--I just used 4, 3, 2, 1 (Not close to what you want--but there are lots of shades of green.) Option Explicit Sub Macro99() Dim numRows As Long Dim iRow As Long Dim LastRow As Long Dim FirstRow As Long Dim myColorIndex As Long numRows = Application.InputBox("How many Rows", Type:=1) If numRows < 1 Then Exit Sub Application.ScreenUpdating = False With ActiveSheet FirstRow = 5 '<-- LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row For iRow = LastRow To FirstRow Step -1 .Rows(iRow + 1).Resize(numRows).Insert .Rows(iRow).Copy _ Destination:=.Rows(iRow + 1).Resize(numRows) If IsNumeric(.Cells(iRow, "D").Value) Then .Cells(iRow + 1, "D").Resize(numRows).Value _ = .Cells(iRow, "D").Value + 110 End If Select Case .Cells(iRow, "W").Value Case Is = 1: myColorIndex = 4 Case Is = 2: myColorIndex = 3 Case Is = 3: myColorIndex = 2 Case Is = 4: myColorIndex = 1 Case Else myColorIndex = xlNone End Select .Cells(iRow + 1, "x").Resize(numRows).Interior.ColorIndex _ = myColorIndex Next iRow End With Application.ScreenUpdating = True End Sub sloanranger wrote: I have one more request, i need to expand on the macro you wrote, this time can you make it turn column X into a colour based on a number in column W the colours i need are red, blue, yellow and green and the are determined by the numbers 4,3,2 and 1 respectively. example X5=35mv X6=70ml X7=35ml X8=70mv dont worry about what X contain, but they must stay (they are the result of a formula) and W5=4 W6=3 W7=2 W8=1 therefore X5 colorindex should be red, X6 should be blue, X7 should be yellow and X8 should be green and all this needs to be applied before the insert and copy loop starts Hope you can help Lee Sloan -- Dave Peterson |
#5
![]() |
|||
|
|||
![]()
are you asking if i only need this for the new rows?
If so the answer is no, i need the colours to be applied before the new rows are inserted Lee Sloan |
#6
![]() |
|||
|
|||
![]()
ive managed to resolve this one myself, i have move the select case
stuff before the isnumeric and it works. Cheers Lee SLoan |
#7
![]() |
|||
|
|||
![]()
Glad you got it working, but if all you did was move those sections around, then
that didn't change anything significant. sloanranger wrote: ive managed to resolve this one myself, i have move the select case stuff before the isnumeric and it works. Cheers Lee SLoan -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Activate a macro to insert a row and copy the formuals from the rows above to the blank row | Excel Discussion (Misc queries) | |||
copy / paste selective rows | Excel Discussion (Misc queries) | |||
Copy conditional formatting across multiple rows? | Excel Discussion (Misc queries) | |||
Copy Word table into Excel cell by cell | Excel Discussion (Misc queries) | |||
Paste rows of numbers from Word into single Excel cell | Excel Discussion (Misc queries) |