Thread: Criptic VB Code
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Criptic VB Code


It can often help if you provide the Operating System and Excel version you are using.
Also specifying the exact error message received is a key.

That said, using the same range variable to loop thru nested loops can cause problems.
Use separate variables... maybe Cell and rCell.

Unless there is only one sheet involved, always prefix range call outs with
the appropriate workbook and sheet references...
Dim wb as Workbook
Dim ws as Worksheet
Set wb = Workbooks("Sludge")
Set ws = wb.Worksheets("Grease")

So this...
For Each cell In Range(rng_3, rng_4)
Could be...
For Each cell In ws.Range(rng_3, rng_4)
(the above assumes rng_3 and rng_4 are on ws)
Or...
For Each cell In rng_3.Parent.Range(rng_3, rng_4)

Practically any John Walkenbach book would ease the OJT.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"El Bee"
wrote in message
Below I am attempting to write some VB code and I now get an error with the
second level of the statement "For Each cell in Range"
can I not have multiple levels of this command like I can with the "IF"
statement.
I really hate the OJT factor so any help with improving the code below would
also be GREATLY appreciated.

Thanks,

El Bee

************

For Each cell In Range(rng_3, rng_4)
If cell.Value = ProgName Then
If InStr(levels, cell.Offset(0, 1).Select) Then
Selection.End(xlToLeft).Select ' get the logon name for search in
Ecometry Data wrksheet
logon = ActiveCell.Value
Sheets("Ecometry Data").Select
For Each cell In Range(rng_1, rng_2)
If cell.Value = logon Then
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
Copy_from = ActiveCell.Address
Sheets("Profiles").Activate
Range(paste_here).Select
Selection.PasteSpecial Paste:=xlPasteAll, operation:=xlNone, _
skipblanks:=False, Transpose:=True
cell.Offset(2, 13).Select
Range(Copy_from).Select
Selection.End(xlToRight).Select
Selection.End(xlToRight).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Profiles").Select
Selection.PasteSpecial Paste:=xlPasteAll, operation:=xlNone,
skipblanks:= _
False, Transpose:=True
Application.CutCopyMode = False
Range(past_here).Select
cell.Offset(0, 3).Select
paste_here = ActiveCell.Address
End If
Next cell
End If
End If
Next cell