need to paste range or rows as values

kxlvba

New Member
Joined
Jun 11, 2006
Messages
43
Hello,
I have about 31 worksheets by name of 1,2,3,4.....31.
Now, I need to find the last entry and from row number 3 to this row I need to paste entries as values. Because there are lookup formulas as well.

I tried using the below mentioned code, but it is not working. Please help.

Chosen 2 because first sheet is INDEX.

Sub update()

Dim ws As Worksheet
Dim kctr, irow As Integer

For kctr = 2 To 32

Set ws = ThisWorkbook.Sheets(kctr)
irow = ws.Cells(Rows.Count, 2).End(xlUp).Row

Rows(irow).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= False, Transpose:=False

kctr = kctr + 1

Next kctr

End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello

try

Code:
Sub update()
Dim ws As Worksheet
Dim kctr, irow As Integer

For kctr = 2 To ActiveWorkbook.Sheets.Count
    With Sheets(kctr)
        .Rows("3:" & Cells(Rows.Count, 2).End(xlUp).Row).Copy
        .Range("A3").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With
Next kctr
End Sub
 

kxlvba

New Member
Joined
Jun 11, 2006
Messages
43
Thanks,
However this codes does the above changes for all worksheets. There is a cell B3 in each worksheet. How do I further place a condition, by which only if cell B3 is populated or <> "", then only paste that worksheets row as values. Rest of the worksheets with no data should be untouched.
 

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello

like this?

Code:
Sub update()
Dim ws As Worksheet
Dim kctr, irow As Integer

For kctr = 2 To ActiveWorkbook.Sheets.Count
    If Not IsEmpty(Sheets(kctr).Range("B3").Value) Then
        With Sheets(kctr)
            .Rows("3:" & Cells(Rows.Count, 2).End(xlUp).Row).Copy
            .Range("A3").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        End With
    End If
Next kctr
End Sub
 

Forum statistics

Threads
1,137,340
Messages
5,680,916
Members
419,945
Latest member
Carrie Sellers

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
Top