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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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