Help with some VBA code

frets2011

New Member
Joined
Feb 26, 2011
Messages
29
I found this VBA code that does exactly what i want, but it keeps deleting my headings on the summary sheet. My question is, is the highlighted code line necessary and if it is what purpose does it serve?


Sub UpdateSummary()
Dim Ws As Worksheet, LstRw As Long
LstRw = Sheets("Summary").Cells(Rows.Count, "A").End(xlUp).Row

With Sheets("Summary")
.Range("A2:B" & LstRw).ClearContents
NxtRw = 2
For Each Ws In ThisWorkbook.Worksheets
If Not Ws.Name = "Template" And Not Ws.Name = "Summary" Then
.Cells(NxtRw, "A").Value = Ws.Range("A2")
.Cells(NxtRw, "B").Value = Ws.Range("B2")
NxtRw = NxtRw + 1
End If
Next Ws
End With

End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi there,

The highlighted row will clear the values only in the range A2 to AX (X = your last row).

Are your headers on row 2?
 
Upvote 0
If there is nothing below the headers then the last row will be row 1, so they will be cleared.

If this is the case, you could maybe add a 1 to the LstRw variable:

Code:
LstRw = Sheets("Summary").Cells(Rows.Count, "A").End(xlUp).Row + 1
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,673
Members
452,937
Latest member
Bhg1984

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
Back
Top