Multiple For/Next

  • Thread starter Thread starter Ramthebuffs
  • Start date Start date
R

Ramthebuffs

I'm trying to run the following code for each cell in range C2:Q16

ActiveCell.NumberFormat = "General"
ActiveCell.Value = ActiveCell.Value

I've put this as a loop, but would like to run it for rows C to
without having to put in Range("c" & I)...Range("d" & I)....ect

For I = 2 To 16
Range("C" & I).Select
ActiveCell.NumberFormat = "General"
ActiveCell.Value = ActiveCell.Value
next


I tried Range(& X & I).select, but it doesn't work. Where x = c to Q

There is probably a way to select a range C2:Q16 and then convert. Ca
anyone help? I'd also like to know how to use two "For" statements i
combination, just for future reference.

Thanks guy
 
Try something like

Dim Rng As Range
For Each Rng In Range("C2:Q16")
Rng.NumberFormat = "General"
Rng.Value = Rng.Value
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Ramthebuffs"
in message
news:[email protected]...
 
Hello Ramthebuffs,

This should do it. You don't need to reassign the cell value in th
loop. You are only changing the format.

Code
-------------------

Dim c

Dim Rng As Range

Set rng = ActiveSheet.Range("C2:Q16")

For Each c In Rng
c.NumberFormat = "General"
Next c
 
You could try:

With Range("C2:Q16")
.NumberFormat = "General"
.Value = .Value
End With

Hope this helps
Rowan
 
Just replace 'ActiveCell' with 'Selection', thus:

With Selection
.Numberformat="General"
.Value= "Whatever"
End With

and it will do it for the whole selected area at once. alternatively, if
you don't want to have to select the area of interest first, just specify it
a range ie replace 'Selection' with 'Range("C2:Q16")'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top