-
WSkjktoo
AskWoody LoungerJohn, How about this version.
First put this at the top of the module to contain the sub that follows:Private Type KeyboardBytes kbByte(0 To 255) As Byte End Type Dim kbArray As KeyboardBytes Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long Private Declare Function GetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long Private Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long Const VK_NUMLOCK As Integer = &H90 Const VK_SHIFT As Integer = &H10 Const VK_CONTROL As Integer = &H11 Const VK_MENU As Integer = &H12 'Alt key Const VK_CAPSLOCK As Integer = &H14
Now here’s the sub. Attach it to a button and run it this way. Hold down control & shift and click the button to get $A$1, just the control key and click gives $A1, just the shift key and click gives A$1, and just a plain click gives A1.
Sub RefSwitcher() Dim ShiftState As Long Dim CntrlState As Long ShiftState = GetKeyState(VK_SHIFT) And 128 CntrlState = GetKeyState(VK_CONTROL) And 128 If ShiftState = 128 And CntrlState = 128 Then With Selection .Formula = Application.ConvertFormula(Formula:=.Formula, _ fromreferencestyle:=xlA1, toreferencestyle:=xlA1, toabsolute:=xlAbsolute) End With ElseIf CntrlState = 128 Then With Selection .Formula = Application.ConvertFormula(Formula:=.Formula, _ fromreferencestyle:=xlA1, toreferencestyle:=xlA1, toabsolute:=xlRelRowAbsColumn) End With ElseIf ShiftState = 128 Then With Selection .Formula = Application.ConvertFormula(Formula:=.Formula, _ fromreferencestyle:=xlA1, toreferencestyle:=xlA1, toabsolute:=xlAbsRowRelColumn) End With Else With Selection .Formula = Application.ConvertFormula(Formula:=.Formula, _ fromreferencestyle:=xlA1, toreferencestyle:=xlA1, toabsolute:=xlRelative) End With End If End Sub
Ken
-
WSkjktoo
AskWoody LoungerJan,
Nope, no command button. I’m running it from the Macro dialog box, and also from a custom menu button.
Ken
-
WSkjktoo
AskWoody LoungerLegare & Jan,
Yes, the cancel button does give me that error too, but so does the OK button. I probably need to reinstall XL to fix this, but I’m not sure that it is worth the effort required. Thanks for your help.
Ken
-
WSkjktoo
AskWoody LoungerLegare, Thanks for responding. Here’s my actual project…although I have the same problem with the snippet as with the actual project.
It’s purpose is to extract the unique values from a selected 1 column list and write it to the target location. The error occurs on the
“Set” statement.Public Sub Extract() Dim rngStartingCell As Range Set rngStartingCell = Application.InputBox(Prompt:="Select a cell in a blank area _ to start the list of unique items", Type:=8) Selection.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:="", _ CopyToRange:=rngStartingCell, Unique:=True End Sub
-
WSkjktoo
AskWoody LoungerRonny,
Take a look at this macro which was written to help create math equations in Excel It uses special code characters in your equation to convert text to super, sub, italic, or characters from the Symbol font. You could probably customize it to suit your needs.
http://www.wopr.com/cgi-bin/w3t/showthread…amp;Main=128269%5B/url%5D
As it stands it doesn’t run on cells with formulas. but if you disable that line it will run and convert the formula to a value.
Regards
Ken -
WSkjktoo
AskWoody LoungerTake a look at this Chip Pearson page. Look for the heading
-
WSkjktoo
AskWoody LoungerApril 5, 2002 at 11:00 pm in reply to: ‘Text to Columns’ problem (Excel 2000)-MULTI-‘Text to Co #580856Alan,
I’ve been experiencing the same difficultly when pasting from other applications. If I’ve used the TextToColumns wizard and identified a delimiter, any subsequent pastes continue to use it as a delimiter.
Here’s a little macro that I wrote to “reset” the delimiters to nulls. Just attach it to a button, select the cell you want to paste to, run the macro, then paste away.
Sub ResetTextPaste() ' Dim strAddress As String ActiveCell.Value = " " strAddress = ActiveCell.Address Selection.TextToColumns Destination:=Range(strAddress), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _ Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _ :=Array(1, 1) ActiveCell.Value = "" End Sub
For those who may be wondering what this is about, this is for when the Paste|Special option gives you these choices: BIFF format, SYLK format, HTML format, Unicode Format or Text format…and you want either Unicode Text or Text Format.
-
WSkjktoo
AskWoody LoungerKevin,
I thought this would be an interesting project, but Jan had a solution before I had a chance to try anything. Anyway, since you still needed an improvement to the code, I (borrowing liberally from Jan
) wrote this code which should detect and format all instances of a pair of formatting codes.
Sub MyAttempt() Dim iChar() As Long Dim sCodeChar As String Dim sTestChar As String Dim sWork As String Dim i As Long Dim j As Long Dim k As Long Dim Index As Long Dim TextLength As Long Dim bFlag As Boolean Const sChars As String = "_^%&#" If Left(ActiveCell.Formula, 1) = "=" Then Exit Sub 'Find number of pairs of formatting codes and redim array TextLength = Len(ActiveCell.Value) For i = 1 To TextLength If InStr(sChars, Mid(ActiveCell.Value, i, 1)) > 0 Then j = j + 1 Next i If j 2 j / 2 Then MsgBox "Code pair is incomplete. Halt formatting procedure" Exit Sub End If j = j / 2 + 1 ReDim iChar(j, 3) Index = 1 'initialize 'loop through each formatting character For i = 1 To 5 'remove all code chars except the relevant code character from text string 'i is the index number for the formatting code sWork = "" sCodeChar = Mid(sChars, i, 1) For j = 1 To TextLength sTestChar = Mid(ActiveCell.Value, j, 1) If InStr(sChars, sTestChar) = 0 Then 'the char is not a formatting char sWork = sWork + sTestChar ElseIf sTestChar = sCodeChar Then 'the char is the relevant formatting char sWork = sWork + sTestChar End If Next j 'Save the starting and ending positions for each actual segment of text to 'be formatted and the formating character's index. Use k to count the instances 'of the formatting character. k = 0 For j = 1 To Len(sWork) If Mid(sWork, j, 1) = sCodeChar Then If Not bFlag Then 'First instance in a pair of codes iChar(Index, 1) = j - k bFlag = True k = k + 1 Else 'Second instance in a pair of codes iChar(Index, 2) = j - k - 1 bFlag = False k = k + 1 iChar(Index, 3) = i Index = Index + 1 End If End If Next j Next i 'Remove all formatting characters from active cell contents sWork = "" For i = 1 To Len(ActiveCell.Value) If InStr(sChars, Mid(ActiveCell.Value, i, 1)) = 0 Then sWork = sWork + Mid(ActiveCell.Value, i, 1) End If Next i ActiveCell.Value = sWork 'Apply formatting For i = 1 To Index - 1 With ActiveCell.Characters(iChar(i, 1), iChar(i, 2) - iChar(i, 1) + 1) Select Case iChar(i, 3) Case 1 ' Underscore .Font.Subscript = True Case 2 ' ^ .Font.Superscript = True Case 3 ' % .Font.Italic = True Case 4 ' & fixed per JohnBF .Font.Bold = True Case 5 ' # Greek .Font.Name = "Symbol" End Select End With Next i End Sub
-
WSkjktoo
AskWoody LoungerSorry, but the “next step” is beyond my knowledge. Perhaps Jan, a true excel guru, can help.
– edited –
What you might consider is keeping a copy of the original formula with the formatting codes in a nearby cell and modify that cell with your new term, copy to the desired location and run the macro, then.Ken
-
WSkjktoo
AskWoody LoungerMarch 21, 2002 at 3:11 am in reply to: Printing A4-ISO paper size on 8.5 X 11 (Excel 97/SR-2) #577630 -
WSkjktoo
AskWoody LoungerHere’s a link to Chip Pearsons Site decribing how to do this:
-
WSkjktoo
AskWoody LoungerOne way to do this is:
1) open your address book
2) in the main window, right click on the group
3) choose Action|Send MailA new email message appears with the individual addresses in the To: box rather than the list name.
HTH
-
WSkjktoo
AskWoody LoungerAssuming your column of numbers starts in A1 and has no blanks except after the last number, you can use this formula to average the last five numbers in the column:
=AVERAGE(OFFSET($A$1,COUNT($A:$A)-5,0,5,1))
HTH
-
WSkjktoo
AskWoody LoungerWassim
I like to build complex formulas first in multiple cells as you suggest. But then I use the following macro to do my “nesting” for me.
I’ve used it on and off for a while and it works fine, but it hasn’t been fully tested, so it may break under some circumstances. I’m sure others can write more elegant code, but I’ve not noticed anything like this on the board. I’m sure others more expert could improve it and make it unbreakable.
Sub ReferenceReplace() Dim RefMaster As Range Dim RefServant As Range Dim MasterFormula As String Dim ServantFormula As String Dim Work As String Dim i As Long Dim j As Long Dim k As Long Dim l As Long Dim x As Long Dim y As Long Dim NotFound As Boolean On Error GoTo Cancelled Set RefMaster = Application.InputBox("Select the cell containing the master formula", Type:=8) Set RefServant = Application.InputBox("Select the cell containing the servant formula", Type:=8) On Error GoTo 0 If RefMaster.Count 1 Or RefServant.Count 1 Then MsgBox "The master and servant references may only be one cell each. Procedure cancelled" Exit Sub End If ServantFormula = RefServant.Formula 'get rid of the equal sign in servant formula if it exists 'add quotes to unquoted text string 'do nothing to plain numbers If Left(ServantFormula, 1) = "=" Then ServantFormula = Right(ServantFormula, Len(ServantFormula) - 1) ElseIf IsNumeric(ServantFormula) Then 'do nothing Else ServantFormula = Chr(34) & ServantFormula & Chr(34) End If NotFound = True For l = 1 To 4 Select Case l Case 1 x = 1: y = 1 Case 2 x = 0: y = 1 Case 3 x = 1: y = 0 Case 4 x = 0: y = 0 End Select Do MasterFormula = RefMaster.Formula 'Debug.Print RefServant.Address(x, y) i = InStr(MasterFormula, RefServant.Address(x, y)) If i > 0 Then NotFound = False j = i + Len(RefServant.Address(x, y)) k = Len(MasterFormula) - j + 1 Work = Left(MasterFormula, i - 1) & ServantFormula Work = Work & Mid(MasterFormula, j, k) RefMaster.Formula = Work End If Loop Until i = 0 Next l If NotFound Then MsgBox ("The servant formula reference was not found in the master formula") End If Cancelled: End Sub
Ken
-
WSkjktoo
AskWoody LoungerEdited by kjktoo on 25-Feb-02 21:50.
Edited to change the word “sheets” to “ranges”
Jan Karel,
Once again you hit the nail on the head in your response. The annoyance here is why Microsoft uses a default collating sequence in VBA that is different from the one used when sorting ranges. Just one more thing to annoy the unwary like me I guess. I suppose it has to do with making VBA consistent with VB or something like that. Anyway…
Thanks for your help.
Ken
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Looking for Microsoft Defender Manuals/Tutorial
by
blueboy714
40 minutes ago -
Win 11 24H2 Home or Pro?
by
CWBillow
4 hours, 2 minutes ago -
Bipartisan Effort to Sunset the ‘26 Words That Created the Internet’..
by
Alex5723
9 hours, 7 minutes ago -
Outlook new and edge do not load
by
cHJARLES a pECKHAM
21 hours, 3 minutes ago -
Problem using exfat drives for backup
by
Danmc
21 hours, 21 minutes ago -
I hate that AI is on every computer we have!
by
1bumthumb
22 hours, 39 minutes ago -
Change Info in the Settings window
by
CWBillow
1 day, 4 hours ago -
Attestation readiness verifier for TPM reliability
by
Alex5723
1 day, 10 hours ago -
Windows Update says that “some settings are managed b your organization”
by
Ed Willers
20 hours, 10 minutes ago -
Use of Gmail rejected.
by
CBFPD-Chief115
20 hours, 50 minutes ago -
WuMgr operational questions
by
Tex265
20 minutes ago -
Beijing’s unprecedented half-marathon: Humans vs. humanoids!
by
Alex5723
2 days, 1 hour ago -
New Phishing Campaign Targeted at Mac Users
by
Alex5723
1 day, 2 hours ago -
Backing up Google Calendar
by
CWBillow
2 days, 8 hours ago -
Windows 11 Insider Preview build 27818 released to Canary
by
joep517
2 days, 20 hours ago -
File Naming Conventions (including Folders)
by
Magic66
1 day, 19 hours ago -
Windows 11 Insider Preview Build 26100.3613 (24H2) released to Release Preview
by
joep517
3 days, 4 hours ago -
Microsoft sends emails to Windows 10 users about EOS
by
Alex5723
2 days, 14 hours ago -
Outlook 2024 importing Calendar and Contacts – FAILURE
by
Kathy Stevens
1 day, 21 hours ago -
Adding Microsoft Account.
by
DaveBRenn
3 days, 5 hours ago -
Windows 11 Insider Preview build 26120.3576 released to DEV and BETA
by
joep517
4 days, 5 hours ago -
Windows 11 Insider Preview Build 22635.5090 (23H2) released to BETA
by
joep517
4 days, 5 hours ago -
Windows 11 won’t boot
by
goducks25
1 day, 21 hours ago -
Choosing virtual machine product for Windows on Mac
by
peterb
3 days, 19 hours ago -
Rest in Peace
by
Roy Lasris
4 days, 23 hours ago -
CISA : Install Windows March 2025 Updates until April 1 or shut down PC.
by
Alex5723
1 day, 21 hours ago -
Google proposes users with incompatible Win 11 PCs to migrate to ChromeOS Flex
by
Alex5723
5 days ago -
Drivers for Epson Perfection V600 Photo – scanner
by
Bookman
1 day, 15 hours ago -
Long Time Member
by
jackpet
5 days, 3 hours ago -
Woody Leonhard (1951–2025)
by
Will Fastie
2 hours, 18 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.