Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coding a dynamic range

Status
Not open for further replies.

MarkBeck

Technical User
Mar 6, 2003
164
CA
I have this code. The formulas in row 4 copy themselves down.

I think this is not running;
Range("c5:bd&(lastrw.value)").Select

What i am trying to do is calculate the results after resize, then paste the results as values. Row 4 is never overwritten, as it contains the formulas.

Thanks

Mark



Sub UpdateCostCalc()

Set ReCalc = ActiveWorkbook.Sheets("Cost")
lastrw = ReCalc.Cells(Rows.Count, "a").End(xlUp).Row

With ReCalc
.Activate
ActiveSheet.Unprotect
.Range("c4:bd4").Copy .Range("c5").Resize(lastrw - 4, 1)
Calculate
Range("c5:bd&(lastrw.value)").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Range("a1").Select
End With
End Sub
 

Try:
Code:
Range("c5:bd[blue]" & (lastrw.value)[/blue]).Select
Although I am not sure about 'bd' in your Range.....

Have fun.

---- Andy
 



Try this...
Code:
Sub UpdateCostCalc()
    Dim reCalc As Worksheet, lastrw As Long

    Set reCalc = ActiveWorkbook.Sheets("Cost")
    lastrw = reCalc.Cells(Rows.Count, "a").End(xlUp).Row

    With reCalc
        .Unprotect
        .Range("c4:bd4").Copy .Range("c5").Resize(lastrw - 4, 1)
        Calculate
        With .Range("c5:bd" & lastrw.Value)
            .Copy
            .PasteSpecial _
                Paste:=xlPasteValues, _
                Operation:=xlNone, _
                SkipBlanks:=False, _
                Transpose:=False
        End With
        
        .Range("a1").Select
    End With
End Sub

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Thanks Andrzejek, Thanks Skip.


Skip.

I get the following compile error;

"Invalid qualifier"

for "Lastrw" within

With .Range("c5:bd" & lastrw.Value)

Mark
 





Code:
With .Range("c5:bd" & lastrw)

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top