HELP. VBA Cell Reference Issue

imback2nite

Board Regular
Joined
Oct 30, 2004
Messages
211
Office Version
  1. 2003 or older
Platform
  1. Windows
The problem that I’m having is when I change the sheet name. For example Employee 5 to Top Cat and run the below code, I get a reference error.


=IF('Employee 5'!J14="","",VLOOKUP('Employee 5'!J14,$A$3:$B$26,2,FALSE))
What I need to do is to be able to change the Sheet name, gather the information and change the sheet name again.....etc.
I use VB to speed up the process.

Sub CommandButton1_Click()
Unload UserForm7
Sheets("Payroll").Select
Application.ScreenUpdating = False
Sheets("Worksheet").Visible = True
Sheets("Worksheet").Select
Range("D5:AF57").Select
Selection.Replace What:=Range("AH9"), Replacement:=Range("AH5")
Range("D1:Q2").Select
Selection.Copy
Sheets("Payroll").Select
Range("D12").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("Worksheet").Select
Range("D5:AF57").Select
Selection.Replace What:=Range("AH5"), Replacement:=Range("AH9")
Range("D1:Q2").Select
Selection.Copy
Sheets("Payroll").Select
Range("D28").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("Worksheet").Visible = False
Range("B1").Select
Application.ScreenUpdating = True
Unload UserForm2
ActiveSheet.Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:= _
True, AllowFormattingCells:=False, AllowFormattingColumns:=False, _
AllowFormattingRows:=False, AllowInsertingColumns:=False, AllowInsertingRows _
:=False, AllowInsertingHyperlinks:=False, AllowDeletingColumns:=False, _
AllowDeletingRows:=False, AllowSorting:=False, AllowFiltering:=False, _
AllowUsingPivotTables:=False, Password:="***"
ActiveSheet.EnableSelection = xlNoRestrictions
MsgBox "Updating Payroll Complete."
End Sub

Cells AH5 and AH9 contain the Employee names.
What happens is I get a #NAME? Error. I look at the formula and it is now from this...
=IF('Employee 5'!J14="","",VLOOKUP('Employee 5'!J14,$A$3:$B$26,2,FALSE))
to this
=IF(Top ‘Cat’!J14="","",VLOOKUP(Top ‘Cat’!J14,$A$3:$B$26,2,FALSE))

The cell reference is now 'Cat' instead of ‘Top Cat’

Is there something wrong with my code that isn’t specific enough or should I be taking a totally different route than the one I’m taking. This is a pivotal part of the spreadsheet…..but things can be changed. Thanks and let me know if I made sense above. I believe this is all the information. I’m using ver. 2003
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Anybody? Anything? Ideas? This is driving me crazy! It should work.....but it doesn't!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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