Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveSheet.Range("topleft").Offset 1

Status
Not open for further replies.

simoncpage

Programmer
Apr 4, 2002
256
GB
ActiveSheet.Range("topleft").Offset(0, i).EntireColumn.Hidden = Check(i)

I have the following code. Check(i) is an boolean array how can I make it so it equals the opposite if Check(1) = True I want it to be false without having to introduce an if structure?

Any help would be great, thanks

Simon
 

Code:
If Check(i) Then
   ActiveSheet.Range("topleft").Offset(0, i).EntireColumn.Hidden = False
Else
   ActiveSheet.Range("topleft").Offset(0, i).EntireColumn.Hidden = True
End If
It's what coding is all about, SP :)

Skip,
 
have you tried

[tt]ActiveSheet.Range("topleft").Offset(0,i).EntireColumn.Hidden = Not Check(i)[/tt]
 
Justin I think I tried that hoping it would display the opposite but it didn't appear to work. I'll try again thanks!
 
At the risk of stating the obvious, why don't you just assign a true or false instead of creating the boolean - then you can have it any way round you like...
Geoff
 
Xlbo

Is there anyway of writing to a vb of a sheet. I know you can add mods and frms by export but can you do this? No one has said it is impossible just that they dont know. Perhaps there is a way round it with coding in a module???
 
I presume you mean dynamically writing code to the code module of a sheet. If this is the case, I'm pretty sure it can be done.
Have never done it myself, but it might be worthwile (temporarily) joining this forum so that you can search their archives - I know that this has been a discussion thread at least a coupla times in the past 6 months or so
- follow the links from here to get to the signup page
HTH
Geoff
 
You can actually add code to any codemodule of a project. The following examples add code to Sheet1, the first getting gthe code from a file and the second assigning some code to a string variable and using that to construct the code.
Code:
Sub InsertVBA_1()
    With ThisWorkbook.VBProject.VBComponents _
        ("Sheet1").CodeModule
        .AddFromFile "C:\TestSub.txt"
    End With
End Sub
     
Sub InsertVBA_2()
Dim strCode As String
    strCode = "Sub Testing()" & vbCrLf
    strCode = strCode & _
    "'Enter your code here" & vbCrLf
    strCode = strCode & "End Sub"
    With ThisWorkbook.VBProject.VBComponents _
        ("Sheet1").CodeModule
        .AddFromString strCode
    End With
End Sub
A.C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top