Capture Value from Changing Cell

Guy27B

New Member
Joined
Mar 22, 2022
Messages
29
Office Version
  1. 365
Platform
  1. Windows
I have set up a spreadsheet with a dashboard. Cell A5 contains a percentage that changes on a daily basis. I would like to capture the value of A5 on the 1st of each month and put it in a table and then create a line graph from this table. Is there a formula I can use to capture A5's value, and put it in a table where it is fixed and doesn't change when A5 changes? Thanks
 
Hi Joe4 - I apologies. I did try what you told me and put the reference to the active workbook at the top of the code, but when the code resulted in the error, I changed it back again. I've put it back in and run it again, but I still get the same error. I did begin to wonder, like you, about the name of my 'Dashboard' worksheet. I even tried changing it in the code to Sheets ("Sheet2").Activate instead, but both names result in the same error.

1650986605575.png
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Why do you keep putting that:
VBA Code:
Set DashboardWorkbook = ActiveWorkbook
line back in there?
I keep removing it, so I am not sure why you keep adding it back in.
You don't need it, you are alredy setting your workbook object variable in the previous line.

Temporarily replace that last section (putting in the correct file path and name) with this and copy/paste a screen print of what it returns:
VBA Code:
'Open Essential Learning MASTER TRACKER v2
Set DashboardWorkbook = Workbooks.Open("C:\Users\MY NAME")

Dim i As Long
Dim shts As String

For i = 1 To DashboardWorkbook.Worksheets.Count
    shts = shts & DashboardWorkbook.Sheets(i).Name & "," & vbCrLf
Next i
   
MsgBox shts
 
Upvote 0
haha, sorry Joe4. That must have been frustrating. I've taken it out now and I understand that the 'Workbooks.Open' line of code makes that Workbook the active one. Thank you.

I added in your new code and here is the Message box contents - it seems to have put the names of all of the worksheets for the excel DashboardWorkbook together! Never seen that before!

1650989141506.png
 
Upvote 0
OK, so it seems to confirm that you do have a sheet named "Dashboard" and there do not appear to be any extra spaces at the beginning or end of that sheet name.
Is the "Dashboard" sheet visible or hidden in that workbook?

If you remove the line I told you and all those temporaru lines, so that you are left with just this in that section:
VBA Code:
'Open Essential Learning MASTER TRACKER v2
Set DashboardWorkbook = Workbooks.Open("C:\Users\MY NAME")
Sheets("Dashboard").Activate
do you still get that error on the last line above?
 
Upvote 0
OK, let's find out which line of code it doesn't like.

Place a breakpoint on the first line of code in that procedure (specifically, this line):
VBA Code:
If Day(Date) <>26 Then Exit Sub

If you are not sure how to do this, then see this:

Then, save and close the Workbook.

Now, open the workbook so that the code runs.
It should stop at the line with the breakpoint.

Once it does that, click on the F8 key repeatedly, to run your code one line at a time, keeping an eye which line of code you are on.
Note the line of code you are on when this error occurs.
This is the line of code we need to focus on.
 
Upvote 0
Done. The error occurs on the last line: 'Sheets("Dashboard").Activate'.
1650992189722.png
 
Upvote 0
That really makes no sense to me!

It shouldn't make a difference, but what if you add this line before the last line:
Rich (BB code):
'Open Essential Learning MASTER TRACKER v2
Set DashboardWorkbook = Workbooks.Open("C:\Users\MY NAME")
DashboardWorkbook.Activate
Sheets("Dashboard").Activate

In theory, you shouldn't need to activate that workbook, because opening that file should make it the active file.
But let's try explicitly activating it and see if that makes any difference.
 
Upvote 0
Exactly the same. The error still occurs on the final line.
1650992722917.png
 
Upvote 0
OK, are you 100% sure that this "Dashboard" worksheet is visible when you open this file?
And there isn't anything "special" about this sheet, is there?

Other than that, I am afraid I there isn't anything else I can do or suggest without having access to this workbook to see exactly what is going on.
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,655
Members
448,975
Latest member
sweeberry

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