VBA Change Sheet Name Reference

FalconFlyer

New Member
Joined
May 18, 2015
Messages
30
Hopefully this is something simple I'm overlooking. I am using the code below to find the last row in another workbook. It works fine, but I would like to change it to reference the Worksheet "Sheet1", not the name of the Worksheet. I do not want problems down the road if someone changes the name. I have tried to change the code, but I cannot figure it out. If anyone can point me in the right direction, that would be helpful.

TIA

Code:
LastRow1 = wkbk.Sheets("Master Summary List").Cells(wkbk.Sheets("Master Summary List").Rows.Count, "A").End(xlUp).Row
wkbk.Sheets("Master Summary List").Cells((LastRow1 + 1), "A") = txt
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
How about
Code:
   For Each ws In wkbk.Worksheets
      If ws.CodeName = "Sheet1" Then Set mws = ws
   Next ws
 
Upvote 0
Untested, but I think this should work:
Code:
With WkBk.Sheet1
    LastRow1 = .Cells(.Rows.Count, "A").End(xlUp).Row
    .Cells((LastRow1 + 1), "A") = txt
End With
 
Upvote 0

Forum statistics

Threads
1,213,524
Messages
6,114,117
Members
448,549
Latest member
brianhfield

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