LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default With stmt and Range

HI - I'm still fuzzy on with stmts and ranges. This sub is used to
copy pieces of an addin ws elsewhere.

top half works fine. I got bottom half to work with the FmWs object,
but I don't understand why the commented out With stmt got the error.
I thought I followed the MSo help docum pretty closely. Guess not 'tho.
Thanks,
Neal Z.



Sub CopyAItmpltCstmRng(TmpltRngIdOrFmLOrow As Variant, FmLOcol As Integer, _
FmHIrow As Long, FmHIcol As Integer, _
ToRow As Long, ToCol As Integer, _
Optional ToWbkNa As String = "", _
Optional ToWsNa As String = "")

' Copies a range of cells from the AddIn TmpltCstm ws to another wbk and ws.
'Default To loca is the active sheet.
'NO error checking is done on these args;
' TmpltRngIdOrFmLOrow is a string of rng to be copied, e.g. "a1" "f2:zz23"
' FmLOcol, FmHIrow, FmHIcol are ignored.
' TmpltRngIdOrFmLOrow is numeric, the lower left row of the copy.
' FmLOcol, FmHIrow, FmHIcol s/b valued to complete the range to
' be copied.

Dim FmWs As Worksheet


' value null optionals
If ToWbkNa = "" Then ToWbkNa = ActiveWorkbook.Name
If ToWsNa = "" Then ToWsNa = ActiveSheet.Name

' do the copy

If VarType(TmpltRngIdOrFmLOrow) = vbString Then

With Workbooks(gAddInNa).Sheets("TmpltCstm").Range(Tmpl tRngIdOrFmLOrow)

.Copy Destination:=Workbooks(ToWbkNa).Sheets(ToWsNa) _
.Cells(ToRow, ToCol)

End With

Else

'' With stmt crapped out with a 1004 error ??
'' With Workbooks(gAddInNa).Sheets("TmpltCstm").Range _
'' (Cells(TmpltRngIdOrFmLOrow, FmLOcol), Cells(FmHIrow, FmHIcol))
''
'' .Copy Destination:=Workbooks(ToWbkNa).Sheets(ToWsNa) _
'' .Cells(ToRow, ToCol)
'' End With

' below works
Set FmWs = Workbooks(gAddInNa).Sheets("TmpltCstm")

FmWs.Range(FmWs.Cells(TmpltRngIdOrFmLOrow, FmLOcol), _
FmWs.Cells(FmHIrow, FmHIcol)).Copy _
Destination:=Workbooks(ToWbkNa).Sheets(ToWsNa) _
.Cells(ToRow, ToCol)

End If
End Sub

--
Neal Z
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
LOOKUP or IF-THEN stmt - which one? JessP27 Excel Worksheet Functions 8 June 1st 09 04:51 PM
If Stmt with two colors kenny4golf Excel Worksheet Functions 1 December 14th 07 09:29 PM
Getting error using if then else stmt ub Excel Worksheet Functions 2 September 24th 07 10:48 PM
URGENT need help with if/then stmt. Melissa H. Excel Worksheet Functions 4 October 26th 05 10:08 PM
SELECT stmt using a range name? mcdowell[_3_] Excel Programming 2 October 15th 03 08:09 AM


All times are GMT +1. The time now is 09:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"