|
-
Jul 17th, 2009, 03:22 PM
#1
Thread Starter
New Member
[RESOLVED] Selection Range in Excel as object variable
I want to select a range of cells of about 1 to 10 rows and 5 to 50 columns from one workbook and based on that selection will set the values in a different workbook. Here is my code that I cannot make work.
Code:
Public Sub DataTransferTwo()
Dim MyRange As Range
Dim Pname As String
Dim Loc As String
Dim Clt As String
Dim MyDate As Date
'
Workbooks("Master Project Status.xls").Worksheets "Proposals").Activate
Set MyRange = Selection.Value (This is far as I get then errors-Object Required or Wrong Method/Property)
With MyRange
MyDate = MyRange("", Range("B1").End(xlDown).Value)
Pname = MyRange("", Range("D1").End(xlDown).Value)
Clt = MyRange("", Range("E1").End(xlDown).Value)
Loc = MyRange("", Range("G1").End(xlDown).Value)
End With
'
Workbooks("Proposal Tracking.xlsx").Worksheets("ACT").Activate
Range("B4000").End(xlUp).Offset(1, 0).Select
Selection = Pname
Range("D4000").End(xlUp).Offset(1, 0).Select
Selection = Clt
Range("E4000").End(xlUp).Offset(1, 0).Select
Selection = Loc
Range("G4000").End(xlUp).Offset(1, 0).Select
Selection = MyDate
End Sub
Any help would be greatly appreciated
Last edited by RobDog888; Jul 20th, 2009 at 12:26 PM.
Reason: Not Sure where this should be posted to what forum
-
Jul 17th, 2009, 03:25 PM
#2
Re: Selection Range in Excel as object variable
Thread Moved
Welcome to the Forums
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 17th, 2009, 03:27 PM
#3
Thread Starter
New Member
Re: Selection Range in Excel as object variable
Where should I have posted this???
-
Jul 18th, 2009, 01:11 AM
#4
Re: Selection Range in Excel as object variable
Set MyRange = Selection.Value (This is far as I get then errors-Object Required or Wrong Method/Property)
you are trying to assign a value to a range object
try
set myrange = selection.range
Where should I have posted this???
here
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 18th, 2009, 06:49 AM
#5
Re: Selection Range in Excel as object variable
In case you haven't noticed the breadcrumb links above the posts (and below them), "here" is the Office Development forum.
You had posted in the VB6 forum, but the "VB Editor" in Office programs is actually VBA rather than VB, so the VB6 forum is not really apt (they have some similarities, but lots of differences too).
-
Jul 20th, 2009, 10:05 AM
#6
Thread Starter
New Member
Re: Selection Range in Excel as object variable
Wesconn1...
Well ....it didn't quite correct the problem.
Code:
Public Sub DataTransferTwo()
Dim Pname As ( I changed this from String to Range to Variant to Long and nothing mattered)
Dim Loc As Variant
Dim Clt As Variant
Dim MyDate As Date
Dim MyRange As Variant
Set MyRange = Selection (This time I got a property error when I included .Range to Selction so I just removed it and it went by only to create another error below)
'
With MyRange
Pname = MyRange("", Range("D1").End(xlDown).Value) ( Now I get Error 13 Typematch)
Clt = MyRange("", Range("E1").End(xlDown).Value)
Loc = MyRange("", Range("G1").End(xlDown).Value)
MyDate = MyRange("", Range("B1").End(xlDown).Value)
End With
'
'
Workbooks("Proposal Tracking.xlsx").Worksheets("ACT").Activate
Range("B4000").End(xlUp).Offset(1, 0).Select
Selection = Pname
Range("D4000").End(xlUp).Offset(1, 0).Select
Selection = Clt
Range("E4000").End(xlUp).Offset(1, 0).Select
Selection = Loc
Range("G4000").End(xlUp).Offset(1, 0).Select
Selection = MyDate
End Sub
I aapreciate any help you can give
thanks VBA666
Last edited by RobDog888; Jul 20th, 2009 at 12:26 PM.
-
Jul 22nd, 2009, 10:16 PM
#7
Re: Selection Range in Excel as object variable
as you give no indication as what part is not working now, hard to make suggestions
do you get error, incorrect result or nothing happen?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 23rd, 2009, 08:49 AM
#8
Thread Starter
New Member
Re: Selection Range in Excel as object variable
 Originally Posted by westconn1
as you give no indication as what part is not working now, hard to make suggestions
do you get error, incorrect result or nothing happen?
I appolgize for not updating this status issue it was resolved after I sent this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|