Intersect Code

slimimi

Well-known Member
Joined
May 27, 2008
Messages
532
Hi there - does anyone know how i can change the formula below to look at specific rows instead please?

Say for example - i wanted to look at rows 5 to 24

Code:
Intersect(Rows(c.Row), Range("F:F,J:J,H:H,L:L,N;N,Q:Q,R:R,S:S")).NumberFormat = myFormat
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You didn't say instead of what? A guess then is:
Code:
Intersect(Rows("5:24"), Range("F:F,J:J,H:H,L:L,N;N,Q:Q,R:R,S:S")).NumberFormat = myFormat
 
Upvote 0
thanks peter - remember this was the code you passed to me last time. I have revisited it but need to modify it a bit. Your guess was correct - thanks.

But it just doesnt seem to be working this time. I pasted (as last time) in the worksheet by right clicking on view code.

Somehow - i am still seeing cells with the wrong number format.
THis is what i have so far:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range
Dim c As Range
Dim myFormat As String

Set myRange = Intersect(Target, Columns("A"))
If Not myRange Is Nothing Then
Application.ScreenUpdating = False
For Each c In myRange
If InStr(UCase(c.Value), "JPY") Then
myFormat = "0.00"
Else
myFormat = "0.0000"
End If
Intersect(Rows("5:24"), Range("F:F,J:J,H:H,L:L,N;N,Q:Q,R:R,S:S,T:T")).NumberFormat = myFormat
Next c
Set myRange = Nothing
Application.ScreenUpdating = True
End If
End Sub
 
Upvote 0
Somehow - i am still seeing cells with the wrong number format.
Perhaps some more detail, sample data or something to work with? Which cell(s) were changed and which cells have the wrong format?

The only think I have noticed in the code so far is in the long "Intersect" line you have N;N. Should this be N:N?
 
Upvote 0
Thanks peter - yes - i know its long - is there a way to shorten that?

I figured out the intersect problem. Its because there are merged cells on the sheet which seem to cause a problem. Is there a way around that please that you might know of?

Thanks in advance and all the best to you.
 
Upvote 0
Its because there are merged cells on the sheet which seem to cause a problem. Is there a way around that please that you might know of?
"Unmerge the cells - they cause lots of problems, particularly in code". That seems to be a fairly common response from vba gurus on this board. :eek:
 
Upvote 0
great thanks peter. How about regarding my loooooonnnnggggg intersect line? :)
The only issue I have with it is what I mentioned two posts ago ( ; instead of : )
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,985
Members
448,935
Latest member
ijat

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