exclude columns in macro

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

I have a simple macro below. I would like to exclude
certain Columns (c). So instead of reading c=5 to 16, it
will be 5 to 8, 10-13.......

p = "C:\Documents and Settings\"
f = "Stuff.xls"
s = "Sheet1"
Application.ScreenUpdating = False
For r = 12 To 72
For c = 5 To 16
a = Cells(r, c).Address
Cells(r, c) = GetValue(p, f, s, a)
Next c
Next r
Range("D:F,I:K,N:O").Select
Selection.NumberFormat = "#,##0_);(#,##0)"

Also, is there a way for me to identify these columns
later on when I am formatting them? So, instead of
D:F,I:K,N:O, i'll have 5-6, 8-10 and so on.

Thanks
 
I might be inclined to attack this way:

Sub Example()
Dim Cell As Range
Dim Rg As Range
Set Rg = Range("D12:F72,I12:K72,N12:O72")
For Each Cell In Rg
Cell.Value = GetValue(p, f, s, Cell.Address)
Next
Rg.NumberFormat = "#,##0_);(#,##0)"
''or
'Rg.EntireColumn.NumberFormat = "#,##0_);(#,##0)"
End Sub
 

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

Similar Threads


Back
Top