Ranges "Set" = I'm Lost

Shiseiji

Board Regular
Joined
Oct 23, 2009
Messages
214
Office Version
  1. 2019
Platform
  1. Windows
Daily I copy two worksheets into a new workbook. The worksheets names change daily so I'm trying to reference the sheets by index number and get the value from Cells(1 , 1). But I'm not getting the ranges set properly for the reference/copy from cells and can't figure it out. My initial attempt was to use "With" but I couldn't get that written properly either.

TIA

Code:
Sub tm_PastUser()'
   Sheet1.Activate
   '
   Dim tCell    As Range
   Dim SumCell  As Range
   '
   Dim ThisWb   As Workbook
   '
   Dim ThisWs   As Worksheet
   Dim OtherWs  As Worksheet
   '
   Set ThisWs = Worksheets(1)
   Set OtheWs = Worksheets(2)
   Set tCell = ThisWs.Cells(2, 5)
   'Set SumCell = ThisWb.OtherWs.Cells(1, 1)
   Set SumCell = ThisWb.Range("OtherWs").Range(Cells(1, 1))
   '
   SumCell.Copy tCell
  Application.CutCopyMode = False
End Sub

As always, I appreciate the help.

Ron
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Would you be able to just explain what you want to accomplish?
 
Upvote 0
Thanks for the response. I mentioned two worksheets, but was only working with one to get the code working. My apologies for the confusion if any over that. I'll address this for a single sheet.

After I copy the worksheet into the workbook it will always be sheets2. It will always have a different name so I can't use the worksheet name in the code and for learning and future use was I am trying to not use count.
So using the Sheets Index number I need the value from A1 (SumCell) copied onto Worksheet("Summary") tCell or Index number sheets1 Cells(2, 5).

Ron
 
Upvote 0
Greeting Mike, and Happy New Year. The code doesn't like my ignorance LOL.
"Object Variable or With Block Variable Not Set" error
Code:
Set SumCell = ThisWb.Range("OtherWs").Range(Cells(1, 1))
 
Upvote 0
Try
Code:
Set SumCell = OtherWs.Cells(1, 1)
 
Upvote 0
There's a typo on this line
Code:
Set OtheWs = Worksheets(2)
you're missing the r.
If you put Option Explicit at the very top of each module(before any code) it will help you to spot tat sort of thing
 
Upvote 0
Thanks for the note on "Option Explicit." I've seen it and should have taken the time to learn what it does.
Code:
SumCell = OtherWs.Cells(1, 1)

Still errors.
 
Upvote 0

Forum statistics

Threads
1,216,577
Messages
6,131,511
Members
449,653
Latest member
andz

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