MAX/MIN in vba not working on inactive sheet

hs2610

New Member
Joined
Apr 23, 2018
Messages
7
I cant the below code to work as it fails if I do not include the activate/select instruction in the code. Portion highlighted in red are the statements where it fails -

Sub data_1min()
rNum_1min = Sheets("data_1min").Cells(1, 1).Value + 1
Sheets("data_1min").Cells(rNum_1min, 2).NumberFormat = "@"
Sheets("data_1min").Cells(rNum_1min, 2).Value = "@" & Application.WorksheetFunction.Text(Application.WorksheetFunction.MRound(Time, "00:01:00"), "hh:mm:ss")
'toFind = Application.WorksheetFunction.MRound(Sheets("data_1min").Cells(rNum_1min, 2).Value, "00:01:00")
toFind = Sheets("data_1min").Cells(rNum_1min, 2).Value
open_1min = Application.WorksheetFunction.Match(toFind, Sheets("Data").Range("C:C"), 0)


count_1min = Application.WorksheetFunction.CountIf(Sheets("Data").Range("C:C"), toFind)
close_1min = Sheets("Data").Cells(open_1min + count_1min - 1, 6).Value


high_1min = Application.WorksheetFunction.Max(Sheets("Data").Range(Cells(open_1min, 6), Cells(open_1min + count_1min - 1, 6)))
low_1min = Application.WorksheetFunction.Min(Sheets("Data").Range(Cells(open_1min, 6), Cells(open_1min + count_1min - 1, 6)))


Sheets("data_1min").Cells(rNum_1min, 4).Value = Sheets("Data").Cells(open_1min, 6).Value
Sheets("data_1min").Cells(rNum_1min, 5).Value = high_1min
Sheets("data_1min").Cells(rNum_1min, 6).Value = low_1min
Sheets("data_1min").Cells(rNum_1min, 7).Value = close_1min
Application.OnTime Application.WorksheetFunction.MRound(Format(Time, "hh:mm:ss"), "00:01:00") + TimeValue("00:01:00"), "data_1min"
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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