Trouble referencing non-selected sheet

mhaines

New Member
Joined
May 23, 2017
Messages
3
I'm having problems altering the value of a single cell on a sheet that I am not currently working in. Here is my code.
Code:
Sub Button1_Click()
    Dim ws As Worksheet
    Dim hold As Integer
    
    
    Worksheets("L1-DIM").Copy _
    Before:=ActiveWorkbook.Sheets("L1-DIM")
    
    Set ws = ActiveSheet
    
    ws.Name = "L1-DIM-" & L1D
    
    Worksheets("Creation").Activate
    upcount = upcount + 1
    L1D = L1D + 1
    hold = upcount + 4
    Set Audit.Range("A1" & hold).Value = upcount
    
End Sub
 
Last edited by a moderator:

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.
To work with a cell on a different sheet you use worksheets to specify witch sheet the cell is on.
For example no mater what sheet is the active sheet this code will set S7 on Sheet2 to 7. If you do not specify a worksheet then the range will be for the current worksheet.
Code:
Worksheets("Sheet2").Range("S7") = 7
 
Upvote 0
You only use Set with objects so it's just:

Code:
Audit.Range("A1" & hold).Value = upcount

assuming that Audit is the codename of the sheet, or a worksheet variable set and declared elsewhere?
 
Upvote 0
I am still receiving an error stating that an object is required. Audit is a sheet defined elsewhere yes.
 
Upvote 0
How is it defined and when is it assigned an object?

Also, that should actually read:

Code:
Audit.Range("A" & hold).Value = upcount
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,930
Members
449,195
Latest member
Stevenciu

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