See attached sample file.
Column “A” & “B” will be added/changed manually.
Row 1 does not change
I need to copy value of “B” to corresponding column [D to I]which matches the value in same row as “A”.
Translated:
A2=”Q”, B2=$10, I need to fill D[“Q”]2 with $10
A3=”R”, B3=$20, I need to fill E[“R”]3 with $20
etc
![]() |
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 |
-
copy value to corresponding cell/column
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » copy value to corresponding cell/column
- This topic has 15 replies, 3 voices, and was last updated 10 years, 3 months ago.
AuthorTopicWSskipro
AskWoody LoungerJanuary 20, 2015 at 5:29 pm #498240Viewing 10 reply threadsAuthorReplies-
Maudibe
AskWoody_MVPJanuary 20, 2015 at 7:21 pm #1485608skipro,
in cell D2 place the formula =IF($A2=D$1,$B2,””)
Copy across to I2 then copy all those cells down
HTH,
Maud -
zeddy
AskWoody_MVPJanuary 21, 2015 at 5:42 am #1485630Hi
Seems like you are processing receipts and amounts to their respective columns.
I would recommend using a dropdown for your entries in column [A], to make sure they are not ‘mistyped’. For example, if you had an entry in column [A] as “Hotell”, it will not be posted to any the [Hotel] column.
You can create a named list of valid entries and use this for the dropdown.zeddy
-
WSskipro
AskWoody LoungerJanuary 21, 2015 at 5:09 pm #1485715Maud,
Thanks. Easy enough [when you know what you are doing].
Since I cannot predict the number of row entries, and other formulas will probably be entered below this section, such as subtotals and other analysis modes [see attached file], can this be done without specifying the actual cells by embedding a formula in each as you suggested. I am thinking of a script that would work in the specific columns with undefined number of rows so the “added” formulas could just be moved down increasing the number of entries that could be entered in the future?
I will not be readily available to modify [add formulas to cells] as needed. -
Maudibe
AskWoody_MVPJanuary 21, 2015 at 6:35 pm #1485762Skipro,
Consider the following code. As long as you start on row 2 and you maintain a blank row between the last pair (in Col A and B) and the Subtotals row, you can add as many rows of data as you like. No formulas needed.
HTH,
MaudCode:Public Sub MatchColums() Dim AvailableRow As Long Dim col As Integer AvailableRow = Range(“A2”).End(xlDown).Row For I = 2 To AvailableRow col = WorksheetFunction.Match(Cells(I, 1), Range(“D1:I1”), 0) + 3 Cells(I, col) = Cells(I, 2) Next I End Sub
-
zeddy
AskWoody_MVPJanuary 22, 2015 at 4:05 am #1485803Hi Maud
..I would use an ‘onEntry’ trigger that, when an entry is made in column , it would match the corresponding column for the adjacent cell (in col [A] ) and directly ‘post’ the entered value to the correct column. No formulas would then be required (making the spreadsheet smaller and faster)
zeddy
-
zeddy
AskWoody_MVP
-
-
-
Maudibe
AskWoody_MVPJanuary 22, 2015 at 4:22 am #1485805 -
WSskipro
AskWoody LoungerJanuary 22, 2015 at 10:58 am #1485864Maud,
Again thank you.Using your last revised sample, if I change a value in “A”, it adds “B” in “D-I” appropriately, great. But it leaves the old value in “D-I”, not so great. I do not know if this was intended due to the idea that the entire column “A” was fixed. It is not and can vary [QQ,R,TTT,UU,VVV] while still using only those already stated options [Q,R,S,T,U,V]. Can “D-I” reflect the current “A,B”, that is only 1 entry per row?
Also, Q-V may change, easy fix, but the user may need to add choices, such as Q-Z. I can change macro as needed, but again I may not be available to do so. Can this be “written” in? -
zeddy
AskWoody_MVPJanuary 23, 2015 at 9:31 am #1486083Hi skipro
see attached file.
I modified Maud’s code to clear the data first, before running the code via the button [Run code]
see sheet named [maud] in attached file.On sheet named [zeddy] in attached file, I use the dropdown method (discussed in earlier post) together with event trapping to place values in the relevant column.
zeddy
-
-
WSskipro
AskWoody LoungerJanuary 23, 2015 at 4:46 pm #1486236 -
Maudibe
AskWoody_MVPJanuary 23, 2015 at 7:31 pm #1486264Skipro,
I Think I have resolved the issues while taking Zeddy’s 2 points into consideration.
The following code removes the button to run the code but instead runs when a change is made in columns A or B. It also performs validation on the changed value that you made.
One question: Suppose you entered a q instead of a Q, would you want the code to change it to uppercase and then match or would you rather have it case sensitive?
HTH,
MaudCode:Private Sub Worksheet_Change(ByVal Target As Range) [COLOR=”#008000″]’——————————- ‘DECLARE AND SET VARIABLES[/COLOR] Dim AvailableRow As Long, LastCol As Long Dim col As Integer LastCol = ActiveSheet.Cells(1, Application.Columns.Count).End(xlToLeft).Column If Intersect(Target, Range(“A2:B13″)) Is Nothing Then Exit Sub [COLOR=”#008000”]’——————————- ‘VALIDATE CHANGED VALUE IN COL A[/COLOR] If Not Intersect(Target, Range(“A2:A13”)) Is Nothing Then For I = 4 To LastCol If Target = Cells(1, I) Then GoTo Continue1 Next I MsgBox “You have entered ” & Chr(34) & Target & Chr(34) & ” which is not a value that matches a column header” Application.EnableEvents = False Target = “” Application.EnableEvents = True Target.Select Exit Sub End If Continue1: [COLOR=”#008000″]’——————————- ‘VALIDATE CHANGED VALUE IN COL B[/COLOR] If Not Intersect(Target, Range(“B2:B13”)) Is Nothing Then If WorksheetFunction.IsNumber(Target) Then GoTo Continue2 MsgBox “You have entered ” & Chr(34) & Target & Chr(34) & ” which a non numeric value in column B” Application.EnableEvents = False Target = “” Application.EnableEvents = True Target.Select Exit Sub End If Continue2: [COLOR=”#008000″]’——————————- ‘PLACE VALUE IN RIGHT COLUMN[/COLOR] Range(“D2:I13”).ClearContents AvailableRow = Range(“A2”).End(xlDown).Row For I = 2 To AvailableRow col = WorksheetFunction.Match(Cells(I, 1), Range(“D1:I1”), 0) + 3 Cells(I, col) = Cells(I, 2) Next I End Sub
-
WSskipro
AskWoody LoungerJanuary 23, 2015 at 8:20 pm #1486266Maud,
Thanks.
I would like it case insensitive.
Are you aware that if an invaild entry is placed in A your message appears and if oked, or if an entry in A is deleted, the cell goes blank. Then if a cell in B is also changed, all entries in D-I below the blank A also go blank. They reappear when a valid entry is placed in the blank cell. -
Maudibe
AskWoody_MVP -
zeddy
AskWoody_MVPJanuary 25, 2015 at 4:32 pm #1486503Hi Maud
..in an ideal world, I would have the range [D2:V13] protected (with or without a password).
Then, in your code, you could add the line to ‘unprotect’ this range prior to making changes, e.g. add
[D2:I13].unprotect
..prior to your
‘PLACE VALUE IN RIGHT COLUMN
Range(“D2:I13”).ClearContents..and then re-protect after changes are made.
The reason for doing this is that at present, a User can ‘manually’ re-type a numeric value
in the block [D2:I13] e.g. ‘post’ a value to a different column than that specified in corresponding column [A] (and even a different amount to that specified in column ). You can even have 2 (or more) values entered in the same row under different columns.
Of course, one answer to the User is ‘don’t do that’.
But see attached example to show what could happen.zeddy
-
-
Maudibe
AskWoody_MVPJanuary 25, 2015 at 4:36 pm #1486504Good point Zeddy!
Adding the line (in blue) should resolve that issue of allowing changes to be made directly in the grid.
Code:Private Sub Worksheet_SelectionChange(ByVal Target As Range) [COLOR=”#0000FF”] If Not Intersect(Target, Range(“D2:I13”)) Is Nothing Then Range(“A1”).Select [/COLOR] Data = Target End Sub
Viewing 10 reply threads -

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
-
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
1 hour, 26 minutes ago -
Out of band for Windows 10
by
Susan Bradley
3 hours ago -
Giving UniGetUi a test run.
by
RetiredGeek
9 hours, 57 minutes ago -
Windows 11 Insider Preview Build 26100.4188 (24H2) released to Release Preview
by
joep517
17 hours, 34 minutes ago -
Microsoft is now putting quantum encryption in Windows builds
by
Alex5723
15 hours, 32 minutes ago -
Auto Time Zone Adjustment
by
wadeer
22 hours, 3 minutes ago -
To download Win 11 Pro 23H2 ISO.
by
Eddieloh
19 hours, 43 minutes ago -
Manage your browsing experience with Edge
by
Mary Branscombe
19 minutes ago -
Fewer vulnerabilities, larger updates
by
Susan Bradley
11 hours, 15 minutes ago -
Hobbies — There’s free software for that!
by
Deanna McElveen
15 hours, 32 minutes ago -
Apps included with macOS
by
Will Fastie
15 hours, 10 minutes ago -
Xfinity home internet
by
MrJimPhelps
15 hours, 5 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
15 hours, 2 minutes ago -
Debian 12.11 released
by
Alex5723
1 day, 19 hours ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
1 day, 22 hours ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
1 day, 2 hours ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
18 hours, 44 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
2 days, 15 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
2 days, 6 hours ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
3 hours, 55 minutes ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
2 days, 10 hours ago -
Some advice for managing my wireless internet gateway
by
LHiggins
1 day, 18 hours ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
20 hours, 14 minutes ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
3 days, 3 hours ago -
Sometimes I wonder about these bots
by
Susan Bradley
16 hours, 4 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
2 days, 14 hours ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
3 days, 17 hours ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
2 days, 1 hour ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
1 day, 14 hours ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
3 days, 20 hours 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.