View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Naeem Naeem is offline
external usenet poster
 
Posts: 13
Default Long VBA Code - Can it be reduced

On Jul 11, 9:47 am, Nm wrote:
On Jul 10, 6:00 pm, Dan Thompson





wrote:
"Dan R." wrote:
Here's a shorter way that works...


Sub Test()
For Each cell In ActiveSheet.Range("A1:C1")
If cell.Value = "YES" Then
Set sh = ThisWorkbook.Worksheets.Add
sh.Name = Range("Sheet_Name_" & cell.Column)
Range("Data_" & cell.Column).Copy _
Sheets(Range("Sheet_Name_" & _
cell.Column).Text).Range("A1")
Sheets(Range("Sheet_Name_" & _
cell.Column).Text).Columns("A").AutoFit
End If
Next cell
End Sub


--
Dan


Gee Thats funny that it works for NM cause when I run Dan R. Code I get a
Run-Time Error "Method 'Range' of 'object '_Global' failed"
Whats with ("Sheet_Name_ ect... ") and ("Data_" ...ect) are they user
variables or are they actual vba commands ?- Hide quoted text -


- Show quoted text -


Hi Dan,

The ("Sheet_Name_ ect... ") and ("Data_" ...ect) are ranges in my
file.

Naeem- Hide quoted text -

- Show quoted text -


Hi Dan,

The ("Sheet_Name_ ect... ") and ("Data_" ...ect) are ranges in my
file.


Naeem