• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Change in-cell tick/check-box value in multiple ranges using SelectionChange

Hi folks


I have a group of cells in $D$23:$I$23 & $D$25:$I$25 that I want to change to Tick/Cross values (a checkbox without using Form Controls or ActiveX Controls) and I have managed to do this with VBA, however the problem comes when trying to copy this to multiplpe ranges within the same sheet.


I can get the my code to copy so far down the sheet but then I see to hit a brick wall with my "Range" selection code.


To be more specific, I have in-cell checkboxes in cell ranges $D$23:$I$23 & $D$25:$I$25 (using hyperlinks instead of using Form Controls or ActiveX controls and using Wingdings font) eg. a "Cross" is =HYPERLINK("","ý") and a "Tick" is =HYPERLINK("","þ").


The Hyperlinks repeat every other 32 rows, so $D$57:$I$57 & $D$59:$I$59 will be the next range(s) and so on every other 32 rows down the sheet. Here's my code;-

[pre]
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

If Target.Cells.Count > 1 Then Exit Sub

If Not Intersect(Target, Range("$D$23:$I$23, $D$25:$I$25, $D$57:$I$57,
$D$59:$I$59, $D$91:$I$91, $D$93:$I$93, $D$125:$I$125, $D$127:$I$127,
$D$159:$I$159, $D$161:$I$161, $D$193:$I$193, $D$195:$I$195, $D$227:$I$227,
$D$229:$I$229, $D$261:$I$261, $D$263:$I$263, $D$295:$I$295, $D$297:$I$297"))

Is Nothing Then

If Target = "ý" Then

Target = "=Hyperlink("""",""þ"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22

Else

Target = "ý"
Target = "=Hyperlink("""",""ý"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22

End If

End If
End Sub
[/pre]

Everything worked as it should until I added another range to the code above ($D$295:$I$295, $D$297:$I$297). Upon which it returns the error "Run time error 1004, Methos 'Range' of object '_Worksheet' failed"


As soon as I remove these ranges from the code it functions as normal.


Is there some kind of undocumented limit to the Range() function? Is there something really simple I am missing?


If there is a simpler way of achieving the result I want to achieve then I am open to suggestions, or if there is a way to offset each range by 32 and cycle through each range until it reaches the end of the data range then that would be favourable, but I don't know with my current level of knowledge if this is achievable or not!


Can anyone shed light on this for me please?


Cheers guys


Alex
 
I'm guessing there's a limit to how many non-continuous ranges you can call out.

Check for multiples, rather than call out every range?

[pre]
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim n1 As Integer
Dim n2 As Integer
Dim d As Integer

If Target.Count > 1 Then Exit Sub

n1 = Target.Row - 23
n2 = Target.Row - 25
'Offset amount
d = 34

'Check if target.row is a row of interest and/or if it's a column of interest
If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) _
Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub

'Do something

End Sub
[/pre]
Just curious, why are you using hyperlinks rather than just a plain value?


EDIT: If this was a worksheet formula, I'd use the MOD function, but I can't seem to get the mod operator to work correctly in VB. I expected:

x = 55-23 mod 32

to return 0. Instead, it just returned 32 for me. If anyone can explain, I'd appreciate it.
 
Hi Again Alex,


I just copied your code to my sheet and it worked perfectly fine, no error at all.


Regards,

Prasad

PS: The only change i made was to put from "If Not Intersect" to "Is Nothing Then" in one line, i did not use underscore to join lines.
 
Luke M, what a star! Thank you very much! Once again your code worked like a charm!


As you've probably guessed, I am relatively new to VB (completely self-taught) and although I know a little, some things are beyond me.


To explain why I am using hyperlinks for my checkbox's - this is simply to get the mouse pointer to behave like a hyperlink "hover" event, so that when the user hovers the mouse over the in-cell "checkboxes", the mouse pointer changes to a "pointing hand" and lets them know they can click on it to change.


Cheers Luke M.


Prasad - Thanks for looking into this, I did actually have my "If Not Intersect" ... "Is Nothing Then" code all on one line, but for ease of viewing (well... I thought so anyway, probably incorrectly), I thought I would break the line up to make it easier to digest.


As always, you guys are always so quick to respond and help out, many thanks!


Alex
 
Hi All,


I wanted to suggest mod function in place of int function. so I was working on the same. I just now refreshed and saw Luke also suggesting the same in his edit. :)


Well, I did not found any issue with usage of mod function. the solution code is here:


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim iStartCell As Integer 'this is first row where your hyperlink is there

Dim iFixedRows As Integer ' size of your form

Dim iCurrCell As Integer ' system will pick on your selection change event


If Target.Count > 1 Then Exit Sub


iStartCell = 23 ' assuming your first hyperlink is here

iFixedRows = 32

iCurrCell = Target.Row


'checking if cell selected in within D and I column

If Target.Column > 3 And Target.Column < 10 Then


If ((iCurrCell - iStartCell) Mod iFixedRows) = 0 Or (iCurrCell = iStartCell) Then


If Target = "ý" Then


Target = "=Hyperlink("""",""þ"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22


Else


Target = "ý"

Target = "=Hyperlink("""",""ý"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22


End If

End If


End If


End Sub


please note

This code will place check/uncheck in any cell if it is within Col D to I and falling in our range rows. if you want hyperlink always to fall in col D then change target as follows:

If Range("D" & Target.Row) = "ý" Then


Range("D" & Target.Row) = "=Hyperlink("""",""þ"")"

Range("D" & Target.Row).Font.Name = "Wingdings"

Range("D" & Target.Row).Font.Underline = False

Range("D" & Target.Row).Font.Size = 22


Else


Range("D" & Target.Row) = "ý"

Range("D" & Target.Row) = "=Hyperlink("""",""ý"")"

Range("D" & Target.Row).Font.Name = "Wingdings"

Range("D" & Target.Row).Font.Underline = False

Range("D" & Target.Row).Font.Size = 22


End If


hope it solves your problem :)


Regards

Prasad
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim iStartCell As Integer 'this is first row where your hyperlink is there

Dim iFixedRows As Integer ' size of your form

Dim iCurrCell As Integer ' system will pick on your selection change event


If Target.Count > 1 Then Exit Sub


iStartCell = 23 ' assuming your first hyperlink is here

iFixedRows = 32

iCurrCell = Target.Row


'checking if cell selected in within D and I column

If Target.Column > 3 And Target.Column < 10 Then


If ((iCurrCell - iStartCell) Mod iFixedRows) = 0 Or (iCurrCell = iStartCell) Then


If Target = "ý" Then


Target = "=Hyperlink("""",""þ"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22


Else


Target = "ý"

Target = "=Hyperlink("""",""ý"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22


End If


End If


End If


End Sub


the above code will put hyperlink in any cell, if selection is within col D to I, and row is within our range. in order to make the hyper link in always col D, irrespective of col, then change condition slightly as below:


If Range("D" & Target.Row) = "ý" Then


Range("D" & Target.Row) = "=Hyperlink("""",""þ"")"

Range("D" & Target.Row).Font.Name = "Wingdings"

Range("D" & Target.Row).Font.Underline = False

Range("D" & Target.Row).Font.Size = 22


Else


Range("D" & Target.Row) = "ý"

Range("D" & Target.Row) = "=Hyperlink("""",""ý"")"

Range("D" & Target.Row).Font.Name = "Wingdings"

Range("D" & Target.Row).Font.Underline = False

Range("D" & Target.Row).Font.Size = 22


End If


hope it solves your prob.


Regards,

Prasad
 
some issue i am facing today, not able to see what I have pasted, twice I hv tried already. :(


Apologies, if it is showing twice for anyone..


Regards,

Prasad
 
trying once again..


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim iStartCell As Integer 'this is first row where your hyperlink is there

Dim iFixedRows As Integer ' size of your form

Dim iCurrCell As Integer ' system will pick on your selection change event


If Target.Count > 1 Then Exit Sub


iStartCell = 23 ' assuming your first hyperlink is here

iFixedRows = 32

iCurrCell = Target.Row


'checking if cell selected in within D and I column

If Target.Column > 3 And Target.Column < 10 Then

If ((iCurrCell - iStartCell) Mod iFixedRows) = 0 Or (iCurrCell = iStartCell) Then

If Target = "ý" Then

Target = "=Hyperlink("""",""þ"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22

Else

Target = "ý"

Target = "=Hyperlink("""",""ý"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22

End If

End If

End If

End Sub


the above code will put hyperlink in any cell, if selection is within col D to I, and row is within our range. in order to make the hyper link in always col D, irrespective of col, then change condition slightly as below:


If Range("D" & Target.Row) = "ý" Then

Range("D" & Target.Row) = "=Hyperlink("""",""þ"")"

Range("D" & Target.Row).Font.Name = "Wingdings"

Range("D" & Target.Row).Font.Underline = False

Range("D" & Target.Row).Font.Size = 22

Else

Range("D" & Target.Row) = "ý"

Range("D" & Target.Row) = "=Hyperlink("""",""ý"")"

Range("D" & Target.Row).Font.Name = "Wingdings"

Range("D" & Target.Row).Font.Underline = False

Range("D" & Target.Row).Font.Size = 22

End If

hope it solves your prob.

Regards,

Prasad
 
trying 4th time


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim iStartCell As Integer 'this is first row where your hyperlink is there

Dim iFixedRows As Integer ' size of your form

Dim iCurrCell As Integer ' system will pick on your selection change event


If Target.Count > 1 Then Exit Sub


iStartCell = 23 ' assuming your first hyperlink is here

iFixedRows = 32

iCurrCell = Target.Row


'checking if cell selected in within D and I column

If Target.Column > 3 And Target.Column < 10 Then

If ((iCurrCell - iStartCell) Mod iFixedRows) = 0 Or (iCurrCell = iStartCell) Then

If Target = "ý" Then

Target = "=Hyperlink("""",""þ"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22

Else

Target = "ý"

Target = "=Hyperlink("""",""ý"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22

End If

End If

End If

End Sub


the above code will put hyperlink in any cell, if selection is within col D to I, and row is within our range. in order to make the hyper link in always col D, irrespective of col, then change condition slightly as below:


If Range("D" & Target.Row) = "ý" Then

Range("D" & Target.Row) = "=Hyperlink("""",""þ"")"

Range("D" & Target.Row).Font.Name = "Wingdings"

Range("D" & Target.Row).Font.Underline = False

Range("D" & Target.Row).Font.Size = 22

Else

Range("D" & Target.Row) = "ý"

Range("D" & Target.Row) = "=Hyperlink("""",""ý"")"

Range("D" & Target.Row).Font.Name = "Wingdings"

Range("D" & Target.Row).Font.Underline = False

Range("D" & Target.Row).Font.Size = 22

End If

hope it solves your prob.

Regards,

Prasad
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim iStartCell As Integer 'this is first row where your hyperlink is there

Dim iFixedRows As Integer ' size of your form

Dim iCurrCell As Integer ' system will pick on your selection change event


If Target.Count > 1 Then Exit Sub


iStartCell = 23 ' assuming your first hyperlink is here

iFixedRows = 32

iCurrCell = Target.Row


'checking if cell selected in within D and I column

If Target.Column > 3 And Target.Column < 10 Then

If ((iCurrCell - iStartCell) Mod iFixedRows) = 0 Or (iCurrCell = iStartCell) Then

If Target = "ý" Then

Target = "=Hyperlink("""",""þ"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22

Else

Target = "ý"

Target = "=Hyperlink("""",""ý"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22

End If

End If

End If

End Sub
 
the above code will put hyperlink in any cell, if selection is within col D to I, and row is within our range. in order to make the hyper link in always col D, irrespective of col, then change condition slightly as below:


If Range("D" & Target.Row) = "ý" Then

Range("D" & Target.Row) = "=Hyperlink("""",""þ"")"

Range("D" & Target.Row).Font.Name = "Wingdings"

Range("D" & Target.Row).Font.Underline = False

Range("D" & Target.Row).Font.Size = 22

Else

Range("D" & Target.Row) = "ý"

Range("D" & Target.Row) = "=Hyperlink("""",""ý"")"

Range("D" & Target.Row).Font.Name = "Wingdings"

Range("D" & Target.Row).Font.Underline = False

Range("D" & Target.Row).Font.Size = 22

End If

hope it solves your prob.

Regards,

Prasad


PS: it was nubmer of char limit that caused by post fail.. anyways 5th time was a success..
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) (http://chandoo.org/forums/topic/select-a-range-via-hyperlink-then-print-selection-automatically) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Dim n1 As Integer
Dim n2 As Integer
Dim d As Integer

If Target.Count > 1 Then Exit Sub

n1 = Target.Row - 23
n2 = Target.Row - 25
'Offset amount
d = 34

'Check if target.row is a row of interest and/or if it's a column of interest
If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) _
Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub

If Target = "ý" Then

Target = "=Hyperlink("""",""þ"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select

Else

Target = "ý"
Target = "=Hyperlink("""",""ý"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select

End If

'==========================Print Currently Selected Indicator===========================
'if you click the cell which has "Print" text ..
If Target.Value = "Print" Then

Dim iCurRw As Integer

'tracks the row number + 1 as you have "print" one row above the print area
iCurRw = Target.Row + 1

'selects C col of given row + 25 rows to I col
Range("C" & iCurRw & ":Q" & (iCurRw + 25)).Select

'the below code prints selected area and one copy
'Selection.PrintOut Copies:=1
'
'End If
Dim xCopies As Integer
On Error Resume Next

Do Until xCopies > 0
xCopies = InputBox("How many copies do you want?", "Copies", 1)

'If Cancel or Esc is pressed, then exit sub
If xCopies = "" Then Exit Sub

Loop
On Error GoTo 0
Selection.PrintOut Copies:=xCopies

End If
'====================================End of Print Code===================================

'==========================Edit Currently Selected Indicator===========================
'if you click the cell which has "Edit *" text ..
If Target.Value = "Q1 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q2 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q3 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q4 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}">
End If

If Target.Value = "Q1 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q2 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q3 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q4 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Notes" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Baseline" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Prev. Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Target" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "National Comparator" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Statistical Neighbour" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If
'====================================End of Edit Code===================================

If Target.Column > 1 Then Exit Sub

ActiveWindow.ScrollRow = ActiveCell.Row

End Sub

Hopefully this makes sense but please let me know if I need to clarify anything.


Sorry for being a pain everyone! I think as I stated in my other post, you solve one problem, only to cause or be confronted with another!


Thanks very much


Alex
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) (http://chandoo.org/forums/topic/select-a-range-via-hyperlink-then-print-selection-automatically) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Dim n1 As Integer
Dim n2 As Integer
Dim d As Integer

If Target.Count > 1 Then Exit Sub

n1 = Target.Row - 23
n2 = Target.Row - 25
'Offset amount
d = 34

'Check if target.row is a row of interest and/or if it's a column of interest
If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) _
Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub

If Target = "ý" Then

Target = "=Hyperlink("""",""þ"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select

Else

Target = "ý"
Target = "=Hyperlink("""",""ý"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select

End If

'==========================Print Currently Selected Indicator===========================
'if you click the cell which has "Print" text ..
If Target.Value = "Print" Then

Dim iCurRw As Integer

'tracks the row number + 1 as you have "print" one row above the print area
iCurRw = Target.Row + 1

'selects C col of given row + 25 rows to I col
Range("C" & iCurRw & ":Q" & (iCurRw + 25)).Select

'the below code prints selected area and one copy
'Selection.PrintOut Copies:=1
'
'End If
Dim xCopies As Integer
On Error Resume Next

Do Until xCopies > 0
xCopies = InputBox("How many copies do you want?", "Copies", 1)

'If Cancel or Esc is pressed, then exit sub
If xCopies = "" Then Exit Sub

Loop
On Error GoTo 0
Selection.PrintOut Copies:=xCopies

End If
'====================================End of Print Code===================================

'==========================Edit Currently Selected Indicator===========================
'if you click the cell which has "Edit *" text ..
If Target.Value = "Q1 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q2 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q3 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q4 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}">
End If

If Target.Value = "Q1 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q2 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q3 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q4 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Notes" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Baseline" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Prev. Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Target" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "National Comparator" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Statistical Neighbour" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If
'====================================End of Edit Code===================================

If Target.Column > 1 Then Exit Sub

ActiveWindow.ScrollRow = ActiveCell.Row

End Sub

Hopefully this makes sense but please let me know if I need to clarify anything.


Sorry for being a pain everyone! I think as I stated in my other post, you solve one problem, only to cause or be confronted with another!


Thanks very much


Alex
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) (http://chandoo.org/forums/topic/select-a-range-via-hyperlink-then-print-selection-automatically) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Dim n1 As Integer
Dim n2 As Integer
Dim d As Integer

If Target.Count > 1 Then Exit Sub

n1 = Target.Row - 23
n2 = Target.Row - 25
'Offset amount
d = 34

'Check if target.row is a row of interest and/or if it's a column of interest
If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) _
Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub

If Target = "ý" Then

Target = "=Hyperlink("""",""þ"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select

Else

Target = "ý"
Target = "=Hyperlink("""",""ý"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select

End If

'if you click the cell which has "Print" text ..
If Target.Value = "Print" Then

Dim iCurRw As Integer

'tracks the row number + 1 as you have "print" one row above the print area
iCurRw = Target.Row + 1

'selects C col of given row + 25 rows to I col
Range("C" & iCurRw & ":Q" & (iCurRw + 25)).Select

'the below code prints selected area and one copy
'Selection.PrintOut Copies:=1
'
'End If
Dim xCopies As Integer
On Error Resume Next

Do Until xCopies > 0
xCopies = InputBox("How many copies do you want?", "Copies", 1)

'If Cancel or Esc is pressed, then exit sub
If xCopies = "" Then Exit Sub

Loop
On Error GoTo 0
Selection.PrintOut Copies:=xCopies

End If

'if you click the cell which has "Edit *" text ..
If Target.Value = "Q1 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q2 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q3 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q4 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q1 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q2 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q3 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Q4 Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Notes" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Baseline" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Prev. Outturn" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Target" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "National Comparator" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Value = "Statistical Neighbour" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If

If Target.Column > 1 Then Exit Sub

ActiveWindow.ScrollRow = ActiveCell.Row

End Sub

Hopefully this makes sense but please let me know if I need to clarify anything.


Sorry for being a pain everyone! I think as I stated in my other post, you solve one problem, only to cause or be confronted with another!


Thanks very much


Alex
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) (http://chandoo.org/forums/topic/select-a-range-via-hyperlink-then-print-selection-automatically) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Dim n1 As Integer
Dim n2 As Integer
Dim d As Integer

If Target.Count > 1 Then Exit Sub

n1 = Target.Row - 23
n2 = Target.Row - 25
d = 34

If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) _
Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub

If Target = "ý" Then

Target = "=Hyperlink("""",""þ"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select

Else

Target = "ý"
Target = "=Hyperlink("""",""ý"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select

End If

If Target.Value = "Print" Then

Dim iCurRw As Integer

iCurRw = Target.Row + 1

Range("C" & iCurRw & ":Q" & (iCurRw + 25)).Select

Dim xCopies As Integer
On Error Resume Next

Do Until xCopies > 0
xCopies = InputBox("How many copies do you want?", "Copies", 1)
If xCopies = "" Then Exit Sub

Loop
On Error GoTo 0
Selection.PrintOut Copies:=xCopies

End If

If Target.Value = "Q1 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q2 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q3 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q4 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q1 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q2 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q3 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q4 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Notes" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Baseline" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Prev. Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Target" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "National Comparator" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Statistical Neighbour" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Column > 1 Then Exit Sub
ActiveWindow.ScrollRow = ActiveCell.Row
End Sub

Hopefully this makes sense but please let me know if I need to clarify anything.


Sorry for being a pain everyone! I think as I stated in my other post, you solve one problem, only to cause or be confronted with another!


Thanks very much


Alex
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) (http://chandoo.org/forums/topic/select-a-range-via-hyperlink-then-print-selection-automatically) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-

[pre]
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Dim n1 As Integer
Dim n2 As Integer
Dim d As Integer

If Target.Count > 1 Then Exit Sub

n1 = Target.Row - 23
n2 = Target.Row - 25
d = 34

If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub
If Target = "ý" Then
Target = "=Hyperlink("""",""þ"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select
Else
Target = "ý"
Target = "=Hyperlink("""",""ý"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select
End If

If Target.Value = "Print" Then
Dim iCurRw As Integer
iCurRw = Target.Row + 1
Range("C" & iCurRw & ":Q" & (iCurRw + 25)).Select

Dim xCopies As Integer
On Error Resume Next

Do Until xCopies > 0
xCopies = InputBox("How many copies do you want?", "Copies", 1)
If xCopies = "" Then Exit Sub
Loop
On Error GoTo 0
Selection.PrintOut Copies:=xCopies
End If

If Target.Value = "Q1 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q2 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q3 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q4 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q1 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q2 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q3 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q4 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Notes" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Baseline" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Prev. Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Target" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "National Comparator" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Statistical Neighbour" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Column > 1 Then Exit Sub
ActiveWindow.ScrollRow = ActiveCell.Row
End Sub
[/pre]

Hopefully this makes sense but please let me know if I need to clarify anything.


Sorry for being a pain everyone! I think as I stated in my other post, you solve one problem, only to cause or be confronted with another!


Thanks very much


Alex
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) (http://chandoo.org/forums/topic/select-a-range-via-hyperlink-then-print-selection-automatically) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-


`Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)


Dim n1 As Integer

Dim n2 As Integer

Dim d As Integer


If Target.Count > 1 Then Exit Sub


n1 = Target.Row - 23

n2 = Target.Row - 25

d = 34


If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub

If Target = "ý" Then

Target = "=Hyperlink("""",""þ"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22

ActiveCell.Offset(-1, 0).Select

Else

Target = "ý"

Target = "=Hyperlink("""",""ý"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22

ActiveCell.Offset(-1, 0).Select

End If


If Target.Value = "Print" Then

Dim iCurRw As Integer

iCurRw = Target.Row + 1

Range("C" & iCurRw & ":Q" & (iCurRw + 25)).Select


Dim xCopies As Integer

On Error Resume Next


Do Until xCopies > 0

xCopies = InputBox("How many copies do you want?", "Copies", 1)

If xCopies = "" Then Exit Sub

Loop

On Error GoTo 0

Selection.PrintOut Copies:=xCopies

End If


If Target.Value = "Q1 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If


If Target.Value = "Q2 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If


If Target.Value = "Q3 Analysis" Then

ActiveCell.Select

Application.SendKeys "{F2}"

End If
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) (http://chandoo.org/forums/topic/select-a-range-via-hyperlink-then-print-selection-automatically) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-


`Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)


Dim n1 As Integer

Dim n2 As Integer

Dim d As Integer


If Target.Count > 1 Then Exit Sub


n1 = Target.Row - 23

n2 = Target.Row - 25

d = 34


If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub

If Target = "ý" Then

Target = "=Hyperlink("""",""þ"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22

ActiveCell.Offset(-1, 0).Select

Else

Target = "ý"

Target = "=Hyperlink("""",""ý"")"

Target.Font.Name = "Wingdings"

Target.Font.Underline = False

Target.Font.Size = 22

ActiveCell.Offset(-1, 0).Select

End If


If Target.Value = "Print" Then

Dim iCurRw As Integer

iCurRw = Target.Row + 1

Range("C" & iCurRw & ":Q" & (iCurRw + 25)).Select


Dim xCopies As Integer

On Error Resume Next
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-

[pre]
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Dim n1 As Integer
Dim n2 As Integer
Dim d As Integer

If Target.Count > 1 Then Exit Sub

n1 = Target.Row - 23
n2 = Target.Row - 25
d = 34

If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub
If Target = "ý" Then
Target = "=Hyperlink("""",""þ"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select
Else
Target = "ý"
Target = "=Hyperlink("""",""ý"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select
End If

If Target.Value = "Print" Then
Dim iCurRw As Integer
iCurRw = Target.Row + 1
Range("C" & iCurRw & ":Q" & (iCurRw + 25)).Select

Dim xCopies As Integer
On Error Resume Next

Do Until xCopies > 0
xCopies = InputBox("How many copies do you want?", "Copies", 1)
If xCopies = "" Then Exit Sub
Loop
On Error GoTo 0
Selection.PrintOut Copies:=xCopies
End If

If Target.Value = "Q1 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q2 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q3 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q4 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q1 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q2 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q3 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q4 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Notes" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Baseline" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Prev. Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Target" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "National Comparator" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Statistical Neighbour" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Column > 1 Then Exit Sub
ActiveWindow.ScrollRow = ActiveCell.Row
End Sub
[/pre]

Hopefully this makes sense but please let me know if I need to clarify anything.


Sorry for being a pain everyone! I think as I stated in my other post, you solve one problem, only to cause or be confronted with another!


Thanks very much


Alex
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-

[pre]
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Dim n1 As Integer
Dim n2 As Integer
Dim d As Integer

If Target.Count > 1 Then Exit Sub

n1 = Target.Row - 23
n2 = Target.Row - 25
d = 34

If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub
If Target = "ý" Then
Target = "=Hyperlink("""",""þ"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select
Else
Target = "ý"
Target = "=Hyperlink("""",""ý"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select
End If
[/pre]
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-

[pre]
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Dim n1 As Integer
Dim n2 As Integer
Dim d As Integer

If Target.Count > 1 Then Exit Sub

n1 = Target.Row - 23
n2 = Target.Row - 25
d = 34

If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub
If Target = "ý" Then
Target = "=Hyperlink("""",""þ"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select
Else
Target = "ý"
Target = "=Hyperlink("""",""ý"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select
End If
[/pre]
 
Slightly off on a tangent, what are the maximum number of characters allowed in a post? I seem to be having trouble pasting in my code...
 
Ahh... A slight problem...


Linked to this post and my earlier post (selecting a range via a hyperlink and then printing selection) - the problem I now face is that my original "Print" code and my "Edit" code listed now no longer function accordingly, my code so far is thus;-

[pre]
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Dim n1 As Integer
Dim n2 As Integer
Dim d As Integer

If Target.Count > 1 Then Exit Sub

n1 = Target.Row - 23
n2 = Target.Row - 25
d = 34

If (n1 - d * Int(n1 / d) <> 0 And n2 - d * Int(n2 / d) <> 0) Or Intersect(Target, Range("D:I")) Is Nothing Then Exit Sub
If Target = "ý" Then
Target = "=Hyperlink("""",""þ"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select
Else
Target = "ý"
Target = "=Hyperlink("""",""ý"")"
Target.Font.Name = "Wingdings"
Target.Font.Underline = False
Target.Font.Size = 22
ActiveCell.Offset(-1, 0).Select
End If

If Target.Value = "Print" Then
Dim iCurRw As Integer
iCurRw = Target.Row + 1
Range("C" & iCurRw & ":Q" & (iCurRw + 25)).Select

Dim xCopies As Integer
On Error Resume Next

Do Until xCopies > 0
xCopies = InputBox("How many copies do you want?", "Copies", 1)
If xCopies = "" Then Exit Sub
Loop
On Error GoTo 0
Selection.PrintOut Copies:=xCopies
End If

If Target.Value = "Q1 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q2 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q3 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q4 Analysis" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q1 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q2 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q3 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Q4 Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Notes" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Baseline" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Prev. Outturn" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Target" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "National Comparator" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Value = "Statistical Neighbour" Then
ActiveCell.Select
Application.SendKeys "{F2}"
End If

If Target.Column > 1 Then Exit Sub
ActiveWindow.ScrollRow = ActiveCell.Row
End Sub
[/pre]

Hopefully this makes sense but please let me know if I need to clarify anything.


Sorry for being a pain everyone! I think as I stated in my other post, you solve one problem, only to cause or be confronted with another!


Thanks very much


Alex
 
Back
Top