Range is not selecting what I want

holy_eti

New Member
Joined
Jun 5, 2018
Messages
38
Hi, I have a small problem with my range option. I am trying to run mycode and it has to format some precise cells. My code seems to be good but when I run it, instead of selecting the range that I want, my macro is selecting the whole sheets so it detroys what I did previously..
Could someone help me please? Thanks

Here's my code :

Code:
For i = 5 To 12
    ThisWorkbook.Sheets(i).Activate


    ThisWorkbook.Sheets(i).Range("J6:J300").Select
    Selection.NumberFormat = "m/d/yyyy"
    ThisWorkbook.Sheets(i).Range("Q6:Q300").Select
    Selection.NumberFormat = "m/d/yyyy"
    ThisWorkbook.Sheets(i).Range("B6:B300").NumberFormat = "General"
Next i
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Sounds like you might have merged cells.
Try
Code:
For i = 5 To 12
    ThisWorkbook.Sheets(i).Range("J6:J300").NumberFormat = "m/d/yyyy"
    ThisWorkbook.Sheets(i).Range("Q6:Q300").NumberFormat = "m/d/yyyy"
    ThisWorkbook.Sheets(i).Range("B6:B300").NumberFormat = "General"
Next i
 
Upvote 0
I've found my error, I was selecting a line that had merged cells so it was included in the selection and my selection was enlarged.
 
Upvote 0
Glad it's sorted & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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