Hit OK for error box in VBA

crockwell

New Member
Joined
Jun 28, 2011
Messages
3
Hello,

I'm writing a code that calculates a histogram on a series of pages in my Excel workbook. The histogram data replaces a preexisting calculated histogram. I can't seem to get my code to ignore the popup box that says Output range will overwrite existing data. Press OK to overwrite data...

I've tried DisplayAlerts=False, EnableEvents=False and ScreenUpdating=False... and none of them can stop the error box coming up for each spreadsheet.

Thank you to anyone in advance!

Here's my code:

Sub NewHistogram()
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
Sheets("0000").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("0001").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("0500").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("1000").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("1500").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("2000").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("2500").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("3000").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("3500").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("4000").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("4500").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Sheets("5000").Select
Histogram ActiveSheet.Range("$b$1:$b$50001"), ActiveSheet.Range("$k$7"), ActiveSheet.Range("$i$8:$i$11"), False, False, False, False
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
What is the code for Histogram?

EDIT: Also, more compactly,

Code:
Sub NewHistogram()
    Dim asWks()     As String
    Dim i           As Long
 
    asWks = aplit("0000 0001 0500 1000 2000 2500 3000 3500 4000 4500 5000", " ")
 
    For i = 0 To UBound(asWks)
        With Worksheets(asWks(i))
            Histogram .Range("B1:$B50001"), .Range("K7"), .Range("I8:I11"), False, False, False, False
        End With
    Next i
End Sub
 
Last edited:
Upvote 0
Code:
aplit("0000 ...

should be

Code:
Split("0000 ...
 
Upvote 0
The code for histogram:

Histogram([inprng],[outrng],[binrng],[pareto],[chartc],[chart],[labels])

where the mandatory ranges are:
inprng=input range
outrng=output range
binrng=bin range

and the options are:
pareto=sorted histogram
chartc=cumulative percentage
chart=chart output
labels

Thank you for the consolidated code. Any ideas on how to get the error messages to stop popping up?

Thanks
 
Upvote 0
That's not the code for Histogram, that is the syntax.

Histogram is not a native function, so a UDF must be defined somewhere. What is that code?
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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