Quick help, on small macro Problem

Lynxador

Board Regular
Joined
Jan 6, 2005
Messages
125
i have this so far.

Code:
Sub Color_format()
Dim x As Long

For x = 6 To 33697 Step 7
Range("E &x:G &x").Select
Selection.Font.ColorIndex = 2
Next x

End Sub

I'm a beginner programmer.. and i always always forget how to set up the range so it uses x as the second value of a cell. any help would be much appreciated.
 

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

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,328
Office Version
  1. 365
Platform
  1. Windows
I'm not sure what you want but does this work:

Code:
Sub Color_format() 
Dim X As Long 

     For X = 6 To 33697 Step 7 
          Range("E" & X & ":G"  & X).Font.ColorIndex = 2 
     Next X 

End Sub

I removed the Select part as you don't always need that to work with a range.

BTW what are you actually tryikng to do - perhaps there is another approach than using a loop.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,328
Office Version
  1. 365
Platform
  1. Windows
Have you tried the code I posted?

Have you tried using Conditional Formatting?
 

Lynxador

Board Regular
Joined
Jan 6, 2005
Messages
125
your code worked perfectly for what i needed. thank you norie :) im gonna try conditional formatting next. im just trying to learn different sloutions to the same problem.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,328
Office Version
  1. 365
Platform
  1. Windows
Well for the conditional formatting you could try something like this.

Select the range you want to format. goto Format>Conditional Formatting..., select Formula is from the dropdown and try this formula:

=MOD(ROW(E1),7)=0

I don't know if this will do exactly what you want.
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,589
Messages
5,765,312
Members
425,272
Latest member
Umba

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
Top