Cells instead of Range - vba

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,508
Hi
How you can replace Cells with Range in the following code. I want to use Cells instead (for learning purpose). Thank you.

Workbooks(1).Worksheets(1).Range("D1:f10").Interior.ColorIndex = 11
 

sheetspread

Well-known Member
Joined
Sep 19, 2005
Messages
5,112
What you have above is best, but:

Workbooks(1).Worksheets(1).Range(cells(1,4),cells(10,6)).Interior.ColorIndex = 11

or:

Workbooks(1).Worksheets(1).cells(1,4).resize(10,3).Interior.ColorIndex = 11
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,004
Office Version
365
Platform
Windows
I think that the first option sheetspread gave should be
Code:
Workbooks(1).Worksheets(1).Range(Workbooks(1).Worksheets(1).Cells(1, 4), Workbooks(1).Worksheets(1).Cells(10, 6)).Interior.ColorIndex = 11
or
Code:
With Workbooks(1).Worksheets(1)
   .Range(.Cells(1, 4), .Cells(10, 6)).Interior.ColorIndex = 11
End With
 

Forum statistics

Threads
1,081,574
Messages
5,359,707
Members
400,545
Latest member
Damntheman30

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top