Jump to content

The Off Topic Thread.


KEN 24T

Recommended Posts

  • less WHY; more WOT
  • Site Developer
  • Member For: 16y 9m 23d
  • Gender: Male
  • Location: Melbourne

I'm trying to set up a macro enabled sheet which can take outputs from a program I use..

Anyway since the program is reporting different trials of data.. But it always reports all the series in a particular project.. What I want to be able to do is be able to hide rows as required by changing the value of a cell right up the top.. between 1 - 10 so to speak.. I can order the output so the preferred options output as say 1-4 and less preferred 5-10.

I've attempted to embed a code in the sheet code.. But it doesn't seem to want to work.. When I run the debugger it doesn't make it past the first line..

Aiming for something that if cell B1 = 1 it hides rows 42-150

= 2 it hides rows 53-150 and so on..

I think the code is right.. I just don't know how to get it to constantly refresh on the cell..

The only way to do that will be programatically through a macro or code (the hiding function). Then you need an "scanning" function that notices when you change cell B1, so it runs automatically some code in the background that chooses the relevant cases (1,2,3 etc) and runs the "hide" code (or separate macro) as necessary for the value that's just been entered into the cell.

if that makes any sense :)

Link to comment
Share on other sites

  • I <3 Floods
  • Silver Donating Members
  • Member For: 13y 6m 1d
  • Gender: Male
  • Location: South West QLD
Sub Test1(ByVal Target As Range)Dim Stubs As IntegerStubs = Range("$B$1").ValueIf Stubs > 10 Then Exit SubEnd IfIf Stubs = "1" Then        Range("42:150").EntireRow.Hidden = TrueElseIf Stubs = "2" Then        Range("53:150").EntireRow.Hidden = TrueElseIf Stubs = "3" Then        Range("64:150").EntireRow.Hidden = TrueElseIf Stubs = "4" Then        Range("75:150").EntireRow.Hidden = TrueElseIf Stubs = "5" Then        Range("86:150").EntireRow.Hidden = TrueElseIf Stubs = "6" Then        Range("97:150").EntireRow.Hidden = TrueElseIf Stubs = "7" Then        Range("108:150").EntireRow.Hidden = TrueElseIf Stubs = "8" Then        Range("119:150").EntireRow.Hidden = TrueElseIf Stubs = "9" Then        Range("130:150").EntireRow.Hidden = TrueElse    End IfEnd Sub

If this helps this is my current code. I just don't know how to jig it to to the auto scan thing..

Link to comment
Share on other sites

  • less WHY; more WOT
  • Site Developer
  • Member For: 16y 9m 23d
  • Gender: Male
  • Location: Melbourne

You'll need a method in here with something along these lines, to trigger the macro you have here. (place inside the 'sheet' of the excel object in the VBA editor, select "worksheet" and "change" in the top selections)

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub

If Not Intersect(Target, Range("B1")) Is Nothing Then

On Error Resume Next

Application.EnableEvents = False

Run Test1()
Application.EnableEvents = True

On Error GoTo 0

End If

End Sub

For the Macro code you posted, change the first line to be ->

Function Test1()

change the last line to be

End Function

Change anywhere it says "Sub" to be "Function" instead. (say it says "Exit Sub", change it to "Exit Function").

The rest looks OK... I think :)

Link to comment
Share on other sites

  • Bronze Donating Members
  • Member For: 13y 9m 8d
  • Gender: Male
  • Location: Victoria

Fark Nitro gym down here was shot the Fark up.. And bombs put in gym.. Thank god I don't train there no more.. Bloody bikie owned gyms!!!

Just heard they had to call in more Police as a bunch of guys pepped up on 1MR, were raging because it's chest day.

Link to comment
Share on other sites

  • I <3 Floods
  • Silver Donating Members
  • Member For: 13y 6m 1d
  • Gender: Male
  • Location: South West QLD

You'll need a method in here with something along these lines, to trigger the macro you have here. (place inside the 'sheet' of the excel object in the VBA editor, select "worksheet" and "change" in the top selections)

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub

If Not Intersect(Target, Range("B1")) Is Nothing Then

On Error Resume Next

Application.EnableEvents = False

Run Test1()

Application.EnableEvents = True

On Error GoTo 0

End If

End Sub

For the Macro code you posted, change the first line to be ->

Function Test1()

change the last line to be

End Function

Change anywhere it says "Sub" to be "Function" instead. (say it says "Exit Sub", change it to "Exit Function").

The rest looks OK... I think :)

Cheers mate.. I'll give it a crack tonight..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
  • Create New...
'