|
-
Jan 12th, 2006, 10:58 PM
#1
Thread Starter
Addicted Member
.range
hi there
I need to display the data from a list of named cells (NameCells) when there is a value for that specific cell.
here is my code
VB Code:
Private Sub PrintTest()
Dim xlApp As Object
Dim xlWkBk As Object
Dim xlSheet As Object
Dim filePath As String
Dim NameVal As String
Dim DescVal As String
Dim DeptVal As String
Dim Purpose As String
' set values
NameVal = "AirCon1"
DescVal = " Air Con"
DeptVal = "IT"
PurposeVal = ""
filePath = "c:\Test Excel\Test.xls"
Set xlApp = CreateObject("Excel.Application")
Set xlWkBk = xlApp.Workbooks.Open(filePath)
Set xlSheet = xlWkBk.Worksheets(1)
With xlSheet
If NameVal <> Null Then
'.Range(get from the NamedCell).Value = NameVal
End If
' and so on
End With
xlWkBk.PrintOut
xlWkBk.Close SaveChanges:=False
xlApp.Quit
Set xlSheet = Nothing
Set xlWkBk = Nothing
Set xlApp = Nothing
End Sub
Private Sub NamedCell(TemplatePath As String, _
Name As String, _
Desc As String, _
Dept As String, _
Purpose As String)
Const NamedCell_Name As String = "Name"
Const NamedCell_Desc As String = " Desc"
Const NamedCell_Dept As String = " Dept"
Const NamedCell_Purpose As String = " Purpose"
End Sub
-
Jan 13th, 2006, 03:13 AM
#2
Thread Starter
Addicted Member
-
Jan 13th, 2006, 01:16 PM
#3
Re: .range
Moved to Office Development
-
Jan 13th, 2006, 01:28 PM
#4
Re: .range
If I understand you correctly your looking for the range of a named range?
VB Code:
'Range "Test" is from A1 to B5 on sheet1
Debug.Print Workbooks(1).Sheets(1).Range("Test").Name
'=Sheet1!$A$1:$B$5
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 
-
Jan 13th, 2006, 06:06 PM
#5
Thread Starter
Addicted Member
Re: .range
i have already named the cells in my test.xls, if the system does not return a value of a specific field for example 'purpose', then i should only get the named cells that is the name, description and department from the sub NamedCell.
-
Jan 13th, 2006, 06:10 PM
#6
Re: .range
Sorry, I dont quite follow you.
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 
-
Jan 13th, 2006, 07:27 PM
#7
Thread Starter
Addicted Member
Re: .range
i know its not clear. the situation is i need to get the named cells from a sub which contains a list of defined named cells when there are data for them. For example,
'for testing
NameVal = "AirCon1"
DescVal = " Air Con"
DeptVal = "IT"
PurposeVal = ""
therefore on my excel report i'm going to have the name , description and department values printed but not 'purpose' because it has no value. This is just a concept i'm testing which will be then implemented in a real world application which will have more than 20 named cells.
-
Jan 14th, 2006, 05:18 AM
#8
Thread Starter
Addicted Member
-
Jan 16th, 2006, 08:55 AM
#9
Frenzied Member
Re: .range
Prav:
I think your "Null" test is your problem. The definition I have for "Null" is:
Null indicates that no space is reserved in memory for the variable.
Here is some code to look at with 3 different tests. Play with it and try to understand how to get all 6 messages to occur (hint: look at the definition of Null closely ... to get the "NOT Null" message you'll have to move some code around!):
Code:
Option Explicit
Sub Macro1()
Dim aRange As Range
'Set a Range variable to refer to a named cell
Set aRange = Range("CellC3") '< NameOf $C$3 was set to "CellC3"
aRange.Select 'Unnecessary - just show that correct cell is loaded in variable
'
'Three different test blocks
If IsNull(aRange) Then
MsgBox "NULL"
Else
MsgBox "NOT Null"
End If
If IsEmpty(aRange) Then
MsgBox "IS EMPTY"
Else
MsgBox "is NOT empty"
End If
If aRange.Value = "" Then
MsgBox "IS EMPTY STRING"
Else
MsgBox "is NOT empty string"
End If
End Sub
I hope this helps.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
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
|