Close Window
Free Ebook
Get Your Free Excel
Top 15 Excel Tutorials from
Instant Access!

Intersect Method Not Working

This code throws an error: Run-time error '1004': Method 'Range' of object '_Worksheet' failed.

Dim myRange As Range
Dim otherRange As Range
Set myRange = Range("B2:D4")
Set otherRange = Range("B3:D5")
With myRange.Interior
.ColorIndex = FillColor + 37
.Pattern = xlSolid
End With
If Not Intersect(Range("otherRange"), Range("myRange")) Is Nothing Then
MsgBox "it works"
End If

Is Intersect method available with Excel 2000, or am I missing something?

Free Excel Courses

Similar Excel Tutorials

Run a macro in Excel when a specific cell is changed; this also covers when a cell within a range of cells is chan ...

How to calculate the total number of working days between two dates in Excel.  This allows you to exclude all weeke ...

I'll show you how to loop through an array in VBA and macros in Excel.  This is a fairly simple concept but it can ...

[file placeholder] ...

Helpful Excel Macros

- This macro allows you to enter any text or number, that you specify, in a cell on which you double-click. In the exampl

- This macro will highlight all cells in excel which are not empty. This means that if a cell contains formulas, text, nu

- This macro will highlight all of the cells in a worksheet which contain a formula. The first one listed will highlight

- This Excel macro filters a selection of data in order to display only the bottom 10 items in the list or data set. This

- List all of the named ranges in a workbook in Excel and the corresponding values stored within every named range. This

Similar Topics

I'm using some basic code below in an on Workbook Open event to format cells with a value less then 2 and less than 1 with a particular color.

The code works, but it really slows my worksheet down when opening. Is there better way to write this? Thanks!


Dim myRange As Range
Dim cell As Range
Set myRange = Range("V6:V50000")
 For Each cell In myRange
 If cell.Value < 2 Then cell.Font.ColorIndex = 5
 If cell.Value < 1 Then cell.Font.ColorIndex = 3

I want to Sum Column "H" starting form "H2" all the way down (rows may vary)
Then Paste My answer in "AM1"
This is what I have so far and for some reason is not working.

myRange = ActiveSheet.Range("H2", Range("H2").End(xlDown))
Range("AM1") = WorksheetFunction.Sum(myRange)

Any Ideas?


This is a very basic question, but i have been struggling for hours, so I must ask.

I I trying to simply fill a combobox on a userform from a named range on a sheet, I want to populate the combobox as soon as the userform starts. (I launch the userform from a button on the sheet) Where must I place the code? and will this code work?

Sub Button1_Click()
Set UserForm1.combobox1.List = Sheets("Sheet1").Range("MyRange")
End Sub

I am very new to vba, so please excuse my ignorance,
any help would be greatly appreciated


Corporate edict.

I have a worksheet that is locked and protected now, except for cells in a certain collumn. I have named the cells in that column "MS96A".

If a user enters a date in a cell or range of cells anywhere in the column, the changed cells also need to be locked and protected (Once they enter a date, it is not allowed EVER to be changed again. Corporate requirement! *Shrug*).

What I am looking for is this. If the user selects that cell again, they will get the usual pop-up message, "The cell or chart that you are trying to change is protected..."

I think I am close, but I am getting an "End If without block If" error on the If Clause.

Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim MRange As Range
Set MRange = Range("MS96A")
' If Not Intersect(Target, MRange) Is Nothing Then For Each cell In MRange Sheets("Sheet1").Unprotect Password:="temp"
cell.Interior.ColorIndex = 3
cell.Font.Color = vbBlack
Selection.Locked = True
Selection.FormulaHidden = False
Next cell
ActiveSheet.Protect Password:="temp", _
DrawingObjects:=False, _
Contents:=True, _
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub

Good day... I need an IF Function that will allow me to action a time in a time range:

... If the time 04:16 falls in the time range 04:00 - 04:29, than put a one (1) in the filed x...
... If the time 04:16 doesn't fall in the time range 04:00 - 04:29, than leave the x fiel empty

Any help is appreciated.


As the title goes this is as simple as it gets. The macro worked good when I was using excel 2003 but now that I have 2007 everything works for except the resizing (Picture.Width & Picture. Height).


Sub AddImage()
Dim strPath As String
Dim strFile As String
Dim Picture As Object
Dim Response As String
Dim C As Range
strPath = "C:\\Photos\"
For Each C In Range("A1", Range("A65536").End(xlUp))
 If C 0 Then
 With C.Offset(0, 1)
 Set Picture = Nothing
 On Error Resume Next
 Set Picture = Sheets("Raw Pix").Pictures.Insert(strPath & C.Value & ".jpg")
 Picture.Top = .Top
 Picture.Left = .Left
 Picture.LockAspectRatio = msoTrue
 Picture.Width = 157
 Picture.Height = 138

 End With
 End If
Next C
End Sub

I have tried to record some macros while I am resizing the pictures but to no avail the macros are blank.

Please help


I am trying to insert a range of cell in the body of an outlook email with the same format. The code I am using now is below and it does insert anything in the email body.


Sub Mail()
Dim OutApp As Object
 Dim OutMail As Object
 Set OutApp = CreateObject("Outlook.Application")
 Set OutMail = OutApp.CreateItem(0)
 On Error Resume Next
 With OutMail
 .To = ""
 .CC = ""
 .BCC = ""
 .Subject = "Burden Report"
 .Body = ActiveSheet.Range("A1:D12")
 .Attachments.Add ("C:\Documents and Settings\cbelcher\Desktop\Burden Report.xls")
End With
 On Error GoTo 0
 Set OutMail = Nothing
 Set OutApp = Nothing
 Set objMsg = Nothing
End Sub

How can i solve a debugger error that states "run-time error '9'...Subscript out of range.

for a search box code provided by Joe Was

I have a workbook that has recently changed on me and is causing a lot of grief. I have a lot of named ranges that the scope of the named range has changed to a new sheet. This is creating a lot of problems! Is there any way to manually change the scope of a named range? without deleting the nmaed range and recreating it?

Hi there! This is definately a quick question, but I need to select a range. I'm looking to do so along these lines:

Range("Activecell.End(xlDown)", "Active.End(xlToRight)").Select

This is definately a problem of not knowing the right jargon to do so.

Could someone please assist?

Thanks in advance!

I am looking for the code to select the visible data after applying a data filter. Actually I know how to select the data after applying the data filter but the issue is I am not able to exclude the header row and give the target range as used (non-blank) rows only!!

I am using below code to Select the Visible rows in the target range:



Problems in this code a

1) after applying the filter, while selecting the data it is selecting all the rows in given range till last row on the workbook. I need this to select the the data only till the last used row in the given range.

2) It is not possible to provide the address of the first row after we apply the filter since the first row address may change depending on the values in the table.

E.g. 1st time when I am running the macro the first row in the visible filtered data is starting at Cell address A4 and next time when I will run the macro it may be A6

3) The Code is also selecting the 1st row which is a header row. How can we exclude it from selection.

Some one please revert with the solution.
Thanks in advance.

Hello all,

Until now I have been able to find all my answers through searches. As a VBA novice, it has been very helpful. I am stumped on this one, however. I am trying to autofill from the selected cell in Column C down. I would like it to stop at the last cell with data in Column B. This is the code I have so far:

Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown))

This does the autofill, but doesn't stop at the last cell with data in Column B.

In the past I have use this code to acheive similar results:

Dim endRow As Long
endRow = Cells(Rows.Count, "B").End(xlUp).Row
Range("C2").AutoFill Destination:=Range("C2:C" & endRow)

The problem with this code is that I will not always be starting in "C2". I need code that uses whatever the selected cell is.

All help is appreciated. Thanks!


How would I concatenate a large range of cells, most of which are blank, and add a comma between each cell's value?
My range is E2:Y2 (I will be filling down), but most of the cells are blank. For example, if I F2=9, I2=11 and X=25, I would like to display them as: 9,11,25.
If in the next row, G=10, K=15 and Y=27, they should look like this: 10,15,27.

Thanks in advance!


Regarding Charts in Excel:

Is there a way to have the Min and Max values adjusted dynamically for the Scale of the values being displayed ??

I know that I can use named ranges to display various sections of data -- month by month, or quarter by quarter, for example.

But when the value of these ranges vary greatly from section to section I end of having to manually go and adjust the Min and Max values of the chart scale.

For example, if I was looking at a graph of the S&P 500's prices last November, a Min and Max range of 750 to 1200 would be fine. But if I had a dynamic range established and scrolled over to view the S&P 500's prices for this past February, I would need a Min and Max range of around 650 to 850.

Is there a way to have these Min & Max values adjust automatically depending on the values being displayed ??



I'm trying to open a pdf file from within excel vba. I have tried using the followhyperlink method but adobe acrobat opens very briefly then immediately closes Code:

Sub OpenPDF()
'Dim pdf As String
 On Error Resume Next
 'pdf file to open
 pdf = "K:\PDF\mypdf.pdf"
 'open the pdf file
 ActiveWorkbook.FollowHyperlink pdf
End Sub

So then I tried to create an instance of acrobat by setting a reference to the acrobat object but I can't get this to work either!

The code I'm using is Code:

Sub OpenPDF()
 Dim pdf As AcroPDDoc
 Dim strPDF As String
 Set pdf = CreateObject("AcroExch.PDDoc")
 'pdf file to open
 strPDF = "K:\PDF\mypdf.pdf"
 'open the pdf file
 pdf.Open strPDF
End Sub

Any ideas what could be wrong with either approach?


Hi all.

I have set up a workbook that is sent out to lots of different users. They each keep and use their own copy.

I have set it up so that everything looks OK and is visible on MY screen, but I'm conscious that some users may have different screen sizes, different toolbars set up, and so on, which might make some parts not immediately visible to them.

I have set up an auto-execute macro which automatically sets the zoom factor to best fit, for several of the worksheets, and this works fine.
Here's the code that does it.

 ActiveWindow.Zoom = True

By repeating this code for each worksheet, I can make each one be zoomed just right.

However, the file contains 8 sheets that are all identically laid out, except the number of rows is different.
What I want to do is go to the worksheet that has the largest number of rows (it's always the same worksheet, so I know which one it is), set the zoom factor for THAT worksheet (which I can do, and it always has the same number of rows), and then take THAT zoom factor, whatever it is - and it will vary depending on the user - and apply that to the other worksheets that have a similar layout.

I could just go through each worksheet and zoom it automatically, but that would mean that some of the sheets looked very large, others very small, and I'd like them to have a consistent appearance.
I could also specify a range on each worksheet that was similar to the appropriate range on the longest worksheet, and zoom that automatically, but that's not ideal either, because some of the row heights vary from sheet to sheet, and again I'll end up with different font sizes.

Anyone know how to do this ?

I use Excel 2000 (9.0.2720)

In range A1:D10, I have entered the figures in actuals (e.g. 34532642.45,
78945624.89 etc.). How can I convert those figures in Lakhs / Thousands /
Crores? Before converting, Can Excel 2000 prompt me for conversion in Lacs /
Thousands / Crores?

Hi all,

I'm looking for help in building a formula which will sort numbers into different "buckets". My spreadsheet has a range of values in column B. These values can range anywhere from -100,000,000 to +10,000,000. I'd like to be able to sort them into the following buckets:-

I am trying to sum all numbers <0 using the SUMIF formula in Excel 2003.

FORMULA: =sumif(range,criteria,sum_range)

I got it to work, but I have cell ranges to total that are not next to each
other (such as A5:A15 and C5:C15).
When selecting the ranges for the formula, Excel writes them A5:A15,C5:C15

because of the comma (,) between the cell ranges Excel is reading the A5:A15
as the range and C5:C15 as the critera. How can I get this formula to allow
me to select multiple cell ranges?

All help is appreciated.

Thank you.


I have the following code to put data from a VBA userform into Excel

Dim Sh As Worksheet
Dim Rng As Range
Set Sh = ActiveSheet
Set Rng = Sh.Range("A65536").End(xlUp).Offset(1, 0)
With Rng
.Cells(1, 1) = Surname.Text
.Cells(1, 2) = forename.Text
.Cells(1, 3) = datein.Text
.Cells(1, 4) = origin.Text
.Cells(1, 5) = Addressee.Value
.Cells(1, 6) = usual.Value
.Cells(1, 7) = dateto.Text
.Cells(1, 8) = permission.Value
.Cells(1, 9) = dateseen.Text
.Cells(1, 10) = requestview.Value
.Cells(1, 11) = Invoice.Value
.Cells(1, 12) = notes.Text
.Cells(1, 13) = datecompleted.Text
.Cells(1, 14) = holdsend.Value
.Cells(1, 15) = fee.Text
.Cells(1, 16) = notes2.Text
.Cells(1, 17) = dateseen.Text
.Cells(1, 18) = invoicesent.Text
.Cells(1, 19) = Paid.Text
.Cells(1, 20) = Complete.Value

End With

What I want to do next is click on the surname on the speadsheet and call up the userform with the fields complete for that person. I would also like to be able to edit/update the form and update the information on the speadsheet accordingly.

Any help would be greatly appreciated!

Many thanks!

I would like to know how to make excel calculate which inventory is left in the FIFO method, quantities that are bought first are the first to be sold. Basically where the quantity and price is derived from.

For example:
bought 100 on FEB 1 $1
bought 500 on FEB 1 $1
bought 1000 on FEB 10 $1
sold 300 on FEB 12 $1.5
bought 100 on FEB 13 $1.1
sold 100 on FEB 13 $1.2
bought 1000 on FEB 14 $1
bought 400 on FEB 15 $1
sold 2000 on FEB 19 $1.5

For this, the formula/function would know that:
=>for the 300 sold on FEB 12, 100 bought on FEB 1 is depleted and 200 of the 500 bought on FEB 1 is depleted.
=>for the 100 sold on FEB 13, the 100 bought on FEB 13 is depleted
=>for the 2000 sold on FEB 19, it knows that:
==>the 100 bought on FEB 1, the 200 of the 500 bought on FEB 1, and the 100 bought on FEB 13 is depleted so it can't consider those quantities
==>it would consider the remaining 300 of the 500 bought on FEB 1, 1000 bought on FEB 10, and 700 of the 1000 bought on FEB 14

The remaining quantities that are left would be the remaining 300 of the 1000 bought on Feb 14 and the 400 bought on FEB 15.

I would like to know for each sold transaction, which quantities at which prices on which day were sold.

Thanks in advance!

Is there any way to stop a macro from running when it gets hung up and my excel is "Not Responding"? Now I have to blow it up which is not a desirable method especially when I have made changes that I wanted to save.

I want to populate a ListBox by means of Method AddItem and List. How to load the Column Heads?

Can be used the RowsourceType Property?


I am looking for a method/formula that will reverse multiple text entries from "abcde" to "edcba". The entries are composed of several words that need to be reversed ie from "ab cde fg" to "gf edc ba"


I am using XL2007 and have a macro that refreshes microsoft query connections. The issue is the refreshes only happen if you step through the macro using the debugger. When you run the macro normally, everything else functions properly, but the data is not refreshed.

Any help is appreciated. Here is an excerpt of the code:

Workbooks.Open Filename:="C:\Profile.xls"
Range("F3").Value = SNR

ActiveWorkbook.Connections("Query from C_Profile").Refresh
ActiveWorkbook.Connections("Query from C_Profile1").Refresh

Related pages

task scheduler vbscriptconversion stone to kilogramcreateobject vbablood pressure chart excelaverageif excel 2010army pt card fillableremove spaces excelvba print to pdfms access unrecognized database formatsnp file extensionvba word tableshow to calculate upper control limitexcel 2010 autosave not workingexcel animated chartspay as you earn calculator kenyaexcelfixgantt chart dependencies excelpcommisna formula excelmultiple digital signatures in excelexcel combobox propertiesedit macro excellock sheet excelcreateobject popupstock market symbol lookupnonlinear curve fitting excelcalculating implied interest ratevb6 subscript out of rangetimesheet with lunchcalculating age from dob in excelexcel constantsid3editorhow to trim column in excelexcel remove blanksexcel conditional vlookuphow to make a cumulative frequency graph in excelhow to make a stacked bar chart in excelmicrosoft excel report card templateunhide all sheets excelwind correction angle calculatorarrange alphabetically in exceltest vba codehow to calculate per diemexcel xirr functionsolidworks vba commandsrandomize excelhow to prevent duplicates in excelwait function in vbadelete multiple rows in excelunprotect excel 2007vendor management excel templateautocorrelation in excelinsert checkbox in excel 2003atpvbaen.xlaadvanced filtering excel 2010time difference calculation in excelgolf handicap calculator spreadsheetctrl p not workingexcel vba copy range to another sheetsubtract on excelnested vlookupcoefficient variation excelsimple interest formula excelexcel bridge graphbiggest loser percentage calculationest convert to pststandardize excel functiondistance in miles between postcodesformula to subtract in excelexcel unique records onlypoint and figure chart exceldynamic chart excelexcel mod functionfree solidworks macrosf4 key in excelexcel application ontimehow to autosum in excel 2007excel hyperlink mailtocreate userform in excel 2007hours worked calculator excelpayslip template free download excel